我有一个时间选择器,一切正常,但问题是我不能让它看起来像设计师想要的那样。现在它看起来像这样:
我需要在按钮下隐藏这个键盘图标。我该怎么做?它只是一个原型(prototype),所以这里只有它的 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>
最佳答案
我刚刚检查了布局检查器中的层次结构并找到了键盘图标。因为纵向和横向层次结构不同,所以我们对此进行了方向检查,还从 Oreo 进行了操作系统检查(从 Oreo 只有这个图标可用),我尝试了这段代码并且工作正常。 PS: Kotlin 代码
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)
{
}
}
}
这样调用
hideKeyboardInputInTimePicker(this.resources.configuration.orientation, startTimePicker)
关于android - 如何关闭 TimePicker 的键盘图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53645448/