我无法更改选择器颜色和TimePicker的其他部分.到目前为止,我可以更改标题颜色和背景,但我无法更改innercircle和textcolor.
更改自定义主题链接.
我的代码:
<TimePicker
android:id="@+id/tp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="clock"
android:headerBackground="#565466"
android:amPmBackgroundColor="#500126"
android:numbersBackgroundColor="#57e326"
android:numbersTextColor="#995394"
android:numbersSelectorColor="#675543"
android:textColorSecondary="#897530"
android:textColorPrimary="#359875"
/>
Run Code Online (Sandbox Code Playgroud) 我正在尝试为sdk 21+(Lollipop)设置TimePickerDialog的样式.到目前为止,我已经想出如何更改XML中的默认colorscheme:
<style name="TimePickerTheme" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">#ff2d6073</item> <!-- no effect -->
<item name="colorPrimaryDark">#ff2d6073</item> <!-- no effect -->
<item name="colorAccent">#ff2d6073</item>
<item name="android:textColor">#ffD0D102</item>
<item name="android:textColorPrimary">#ffD0D102</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这有效,但我正在寻找我可以更改的所有属性的指南或文档.
但是,例如,我需要更改对话框"标题"中的大文本(显示当前所选时间)的属性?
是否有一些文档列出了您可以更改的所有内容?
我正在创建一个 Wear OS 应用程序,并为用户提供设置计时器的选项。除了语音命令,我还想提供手动设置持续时间的选项。
我可以调整时间选择器对话框以适应屏幕,但据我所知,没有本地磨损特定组件或对话框可以选择持续时间。
Wear OS 2.0有一个很好的方法可以从内置的计时器应用程序中选择持续时间,但我没有找到有关用于创建它的组件以及它们是否可用的任何信息。
我真的只是在寻找一种用户友好的方式来设置持续时间。任何帮助或指导将不胜感激!我对 Android 开发很陌生。
希望这里有一个解决方案,我在main.xml中有一个XML TimePicker和ScrollView,并且设置时TimePicker不会滚动.如果我删除ScrollView,Timepicker会滚动得很好,但显然我需要两者.
看起来他们都在争取触摸事件,但这会引发问题.
这是我的代码:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@color/backgroundmain">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Action Title -->
<ImageView />
<TextView />
<!-- Description -->
<TextView />
<!-- Have to Button -->
<TextView />
<RelativeLayout
android:id="@+id/TimePickerSection"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dp"
android:layout_centerHorizontal="true"
android:layout_below="@id/">
<TimePicker
android:id="@+id/TimePick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_below="@id/HaveToText"/>
<Button
android:id="@+id/OkButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/OkText"
android:layout_below="@id/HaveToText"
android:textSize="20sp"
android:onClick="TimePickButton"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/TimePick"/>
</RelativeLayout>
<!-- OR -->
<TextView />
<!-- buttons -->
<TextView />
<Button />
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我删除了不相关的代码,但保留大纲只是为了向您展示布局的布局.
XML中是否有修复?我尝试了类似android:fillViewPort=""但没有做任何事情的事情.我的TimePicker不是Dialog或其他任何东西的一部分,希望我能保持这种方式.
每当我点击Timepicker时,我一直都会遇到这个问题.任何其他设备上不会发生此问题,以下是错误日志:
Error log:
java.lang.NullPointerException
at android.widget.TimePicker.updateInputState(TimePicker.java:846)
at android.widget.TimePicker.onSaveInstanceState(TimePicker.java:561)
at android.view.View.dispatchSaveInstanceState(View.java:13117)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2822)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2828)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2828)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2828)
at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:2828)
at android.view.View.saveHierarchyState(View.java:13100)
at com.android.internal.policy.impl.PhoneWindow.saveHierarchyState(PhoneWindow.java:1930)
at android.app.Dialog.onSaveInstanceState(Dialog.java:407)
at android.app.TimePickerDialog.onSaveInstanceState(TimePickerDialog.java:216)
at android.app.Activity.saveManagedDialogs(Activity.java:1269)
at android.app.Activity.performSaveInstanceState(Activity.java:1187)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1240)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3309)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3369)
at android.app.ActivityThread.access$1000(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1338)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud) 我想创建一个控件,允许用户在我的Android活动中选择一周中的某一天(星期一)和一天中的某个时间(下午1:00).没找到任何好帖子?
我在我的应用程序中使用时间选择器对话框.我也使用appcompat来提供我的应用程序材料设计主题.然而,对话框保持默认的蓝绿色强调色(我的重点是淡蓝色).
所以在我的代码中,我尝试将对话框主题设置为我自己的,并且它接受它使其全屏
mTimePicker = new TimePickerDialog(ctx, R.style.AppTheme new TimePickerDialog.OnTimeSetListener() {->}, hour, minute, DateFormat.is24HourFormat(context));
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何设置TimePickerDialog以正确显示我的颜色而不是默认颜色?
我正在使用此链接Android TimePickerDialog设置最大时间.
我是android新手.借助此代码,我无法选择过去的时间,但我们无法选择未来的时间.在timepickerdialog模式中选择12时,根据第二天而不是过去一天自动更改为am.
java android android-fragments android-studio android-timepicker
继续以下链接中提到的问题:
我可以解决这个问题但它只适用于你使用实际的键盘.如果您使用软键盘,我无法使用它.
我正在编写1.6版本的框架.
任何帮助都感激不尽.
PS:事实上,我到处寻找答案而无法找到它,这告诉我这一定非常简单或非常复杂.救命?!
我是一名法国 Android 开发人员,因此使用Locale.getDefault()会导致我DateFormat使用 24 小时模式。但是,当我通过设置菜单DateFormat将设备手动设置为 12 小时模式时,会继续以 24 小时格式运行。
相反,TimePickers 是根据我自己的 12/24 小时设置来设置的。
有没有办法让DateFormats 的行为与 s 相同TimePicker?
编辑:
这是我的DateFormat声明:
timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
Run Code Online (Sandbox Code Playgroud)
这是我将我设置TimePicker为 12 或 24 小时模式的地方。
tp.setIs24HourView(android.text.format.DateFormat.is24HourFormat((Context) this));
Run Code Online (Sandbox Code Playgroud)
我的解决方案:
根据下面@Meno Hochschild 的回答,这是我解决这个棘手问题的方法:
boolean is24hour = android.text.format.DateFormat.is24HourFormat((Context) this);
tp.setIs24HourView(is24hour); // tp is the TimePicker
timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
if (timeFormat instanceof SimpleDateFormat) {
String pattern = ((SimpleDateFormat) timeFormat).toPattern();
if (is24hour) {
timeFormat = …Run Code Online (Sandbox Code Playgroud)