gcl*_*cl1 11 android android-widget android-datepicker android-layout
datepicker中的默认文本大小对我的应用来说太大了.我已经看到了一种建议在这里改变它的方法,但是为了嵌套在datepicker类中的textviews而钓鱼似乎很笨拙且容易出错.
有更好/更清洁的方法吗?
将主题设置为DatePicker布局并添加android:textSize到它对我有用。
在您的布局的 xml 中添加一个DatePicker应用主题,如下所示 -
<DatePicker xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="@style/NumberPickerStyle"
android:datePickerMode="spinner"
android:calendarViewShown="false"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)
然后像这样定义NumberPickerStyleinstyles.xml指定android:textSize-
<style name="NumberPickerStyle">
<item name="android:textSize">@dimen/number_picker_text_size</item>
</style>
Run Code Online (Sandbox Code Playgroud)
小智 5
更改datepicker/timepicker/numberpicker字体大小的最简单方法是自定义主题.
在样式文件中,按以下方式设置默认字体大小.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:textSize">22sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
Pin*_*nki -2
使用下面的代码
DatePicker picker = (DatePicker)findViewById(R.id.dp_date);
ViewGroup childpicker
= (ViewGroup)
findViewById(Resources.getSystem().getIdentifier("month" /*rest is:
day, year*/, "id", "android"));
EditText textview = (EditText)
picker.findViewById(Resources.getSystem().getIdentifier("timepicker_input",
"id", "android"));
textview.setTextSize(30);
textview.setTextColor(Color.GREEN);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14005 次 |
| 最近记录: |