Wir*_*ing 10 android android-appcompat android-theme material-design
在将appcompat库更新到最新版本(v21)以应用材质设计之后,我的自定义主题不再在Android 4.0.X设备上使用,除非我在XML中明确声明它.
我在Android 2.3.X和5.0.0设备上测试了主题,它可以在这些设备上运行.但它不适用于我的HTC One S和Android 4.0.3.我需要做些什么来解决这个问题?
我的themes.xml
<style name="Theme.Custom" parent="@style/Theme.AppCompat.Light">
<item name="android:editTextStyle">@style/Custom.Widget.EditText</item>
<item name="android:buttonStyle">@style/Custom.Widget.Button</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的styles.xml
<style name="Custom.Widget.EditText" parent="android:Widget.EditText">
<item name="android:background">@drawable/edit_text_holo_light</item>
<item name="android:textColor">@color/text_primary</item>
<item name="android:textColorHint">@color/text_hint_color</item>
</style>
<style name="Custom.Widget.Button" parent="android:Widget.Button">
<item name="android:background">@drawable/btn_default_holo_light</item>
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">64dip</item>
<item name="android:textColor">@color/button_text_primary</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的布局文件
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<!-- other elements -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
android:id="@+id/view_username_edit_username_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|textCapSentences"
android:hint="@string/UsernameScreen_usernameHint"
android:imeOptions="actionDone"
android:singleLine="true"
android:maxLength="@integer/username_max_length"
android:textSize="@dimen/text_size_medium" />
<Button
android:id="@+id/view_username_save_Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view_username_edit_username_editText"
android:clickable="true"
android:enabled="false"
android:orientation="horizontal"
android:text="@string/common_save" />
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
如果我将以下内容添加到布局文件中的行,则可以使用.所以themes.xml似乎出了问题.
style="@style/Custom.Widget.EditText"
style="@style/Custom.Widget.Button"
Run Code Online (Sandbox Code Playgroud)
结果:
预期:
编辑
我在其他一些设备上测试了相同的代码.
我不明白为什么它不适用于某些设备.
小智 6
我添加buttonStyle后没有"android:"前缀,它解决了问题.(name ="android:buttonStyle" - > name ="buttonStyle")
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="buttonStyle">@style/SkinedButton</item>
</style>
Run Code Online (Sandbox Code Playgroud)
最后我找到了解决我的问题的方法。@style/Theme.AppCompat
我作为我的一种风格的家长使用。更改后,它@style/Theme.AppCompat.Light.DarkActionBar
适用于所有设备。我仍然觉得很奇怪为什么这会搞砸我的造型。
归档时间: |
|
查看次数: |
3240 次 |
最近记录: |