Android 时间选择器
在最近做实验编码过程中,又用之前写的一个题目
前言
因为自己有本书Android的用户界面设计,就感觉之前的ui布局不是特别的符合,就重新写了一些ui界面,然后发现当时对于时间选择器的代码编写,是写在类的方法里面的,如果我要在很多地方都使用时间选择器,就要方法写很多次,就想着可不可以封装起来,也方便以后使用
终于是经过很多次的闪退之后,突然开窍就封装好了
可能其中还是有可以进行优化的部分
不过时间选择器还是单独写在另一个类里面了
简单布局
布局还有一些功能没有时间,例如确定按钮,主要只是说明时间选择器
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:divider="@drawable/line"
app:dividerPadding="5dp"
app:showDividers="end|middle"
tools:context=".ui.MeetingTime">
<androidx.appcompat.widget.Toolbar
android:id="@+id/time_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FFBB86FC"
app:contentInsetStart="0dp"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|snap">
<ImageView
android:id="@+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/remove"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="会议室预约"
android:textColor="@color/white"
android:textSize="20sp" />
</androidx.appcompat.widget.Toolbar>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="90dp"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="主题"
android:textColor="#000"
android:textSize="21sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
andro