如果应用程序主题是 Material,如何为某些视图使用 Holo 样式?
How to use Holo style for some views if application theme is Material?
我有一个 Android 应用程序,其中应用程序主题在 styles.xml
中定义如下:
<style name="AppTheme" parent="android:Theme.Material">
</style>
(我知道它需要API 21级)
但我想在某些视图中使用 Theme
或 Theme.Holo
中的一些旧样式。
我在 Nexus 4 上用 Android 5.1 API 22.
测试了它
它适用于进度条:
<ProgressBar
style="@android:style/Widget.ProgressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:indeterminate="true" />
<ProgressBar
style="@android:style/Widget.Holo.ProgressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:indeterminate="true" />
<ProgressBar
style="@android:style/Widget.Material.ProgressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:indeterminate="true" />
在这种情况下,我看到了 3 个不同样式的进度条,但它不适用于 EditText:
<EditText
style="@android:style/Widget.EditText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="test test"
/>
<EditText
style="@android:style/Widget.Holo.EditText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="test test"
/>
<EditText
style="@style/CustomEditText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="test test"
/>
其中 CustomEditText
是:
<style name="CustomEditText" parent="@android:style/Widget.Holo.EditText">
</style>
但是 Material 主题中的所有这些 EditText。
如果主题是 Material
,如何显示 EditText
和 Holo
主题?
将 android:theme
属性设置为 Theme.Holo
。
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
style="@android:style/Widget.Holo.EditText"
android:theme="@android:style/Theme.Holo.Light"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="test test" />
我有一个 Android 应用程序,其中应用程序主题在 styles.xml
中定义如下:
<style name="AppTheme" parent="android:Theme.Material">
</style>
(我知道它需要API 21级)
但我想在某些视图中使用 Theme
或 Theme.Holo
中的一些旧样式。
我在 Nexus 4 上用 Android 5.1 API 22.
测试了它它适用于进度条:
<ProgressBar
style="@android:style/Widget.ProgressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:indeterminate="true" />
<ProgressBar
style="@android:style/Widget.Holo.ProgressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:indeterminate="true" />
<ProgressBar
style="@android:style/Widget.Material.ProgressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:indeterminate="true" />
在这种情况下,我看到了 3 个不同样式的进度条,但它不适用于 EditText:
<EditText
style="@android:style/Widget.EditText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="test test"
/>
<EditText
style="@android:style/Widget.Holo.EditText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="test test"
/>
<EditText
style="@style/CustomEditText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="test test"
/>
其中 CustomEditText
是:
<style name="CustomEditText" parent="@android:style/Widget.Holo.EditText">
</style>
但是 Material 主题中的所有这些 EditText。
如果主题是 Material
,如何显示 EditText
和 Holo
主题?
将 android:theme
属性设置为 Theme.Holo
。
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
style="@android:style/Widget.Holo.EditText"
android:theme="@android:style/Theme.Holo.Light"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:hint="test test" />