Vol*_*yrH 4 android android-timepicker
I have a timepicker, everything works well but the problem is that I can't make it look like designer wants. For now it looks like this:
I need to hide this keyboard icon under the buttons. How can I do it? It's just a prototype, so here's only its xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:tag="ww">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:amPmBackgroundColor="#6400AA"
android:numbersSelectorColor="#6400AA" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal">
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Cancel"
android:textColor="#6400AA" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OK"
android:textColor="#6400AA" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我刚刚在布局检查器中检查了层次结构,发现了那个键盘图标。对于纵向和横向层次结构是不同的,因此我们对此进行了方向检查,并且还从 Oreo 进行了 OS 检查(来自 Oreo 仅此图标可用),我尝试了此代码并且它工作正常。PS:科特林代码
fun hideKeyboardInputInTimePicker(orientation: Int, timePicker: TimePicker)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
try
{
if (orientation == Configuration.ORIENTATION_PORTRAIT)
{
((timePicker.getChildAt(0) as LinearLayout).getChildAt(4) as LinearLayout).getChildAt(0).visibility = View.GONE
}
else
{
(((timePicker.getChildAt(0) as LinearLayout).getChildAt(2) as LinearLayout).getChildAt(2) as LinearLayout).getChildAt(0).visibility = View.GONE
}
}
catch (ex: Exception)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
像这样打电话
hideKeyboardInputInTimePicker(this.resources.configuration.orientation, startTimePicker)
Run Code Online (Sandbox Code Playgroud)
据我所知,您无法删除此图标,它是 Android O 上 UI 的一部分。
该图标的存在是为了使手动编辑时间更加明显,因为在以前的版本中,您可以单击时间并通过键盘更改它并不明显