KKC*_*KKC 24 android datepicker timepicker android-layout
有没有办法更改DatePicker和TimePicker对话框的默认颜色?
这是我试过的代码
<DatePicker
style="@style/date_picker"
android:background="#6495ED"
android:id="@+id/DatePicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" />
<TimePicker
android:id="@+id/TimePicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" />
Run Code Online (Sandbox Code Playgroud)
只有两行改变背景颜色,我想更改日期和时间选择器的默认银色.
请帮忙.
style="@style/date_picker"
android:background="#6495ED"
Run Code Online (Sandbox Code Playgroud)
God*_*win 30
更改选择器对话框的最佳方法是向其添加自定义样式.
<style name="TimePickerTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/color_primary</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
TimePickerDialog timePicker = new TimePickerDialog(mContext, R.style.TimePickerTheme, fromListener, hour, min, false);
Run Code Online (Sandbox Code Playgroud)
为我工作完美.
您必须创建自定义主题并将其保存在某些目录中,以便最终将此主题设置为应用程序的默认主题
首先,在值中添加一个这样的themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Any customizations for your app running on pre-3.0 devices here -->
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
然后,在res目录中创建一个名为"values-v11"(Android 3.0+)的目录,并放置一个这样的themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
<!-- Any customizations for your app running on 3.0+ devices here -->
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
最后,在res目录中创建一个名为"values-v14"(Android 4.0+)的目录,并创建一个themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyAppTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar">
<!-- Any customizations for your app running on 4.0+ devices here -->
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
最后在manifest.xml中
<application
...
android:theme="@style/MyAppTheme">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41870 次 |
| 最近记录: |