【发布时间】:2014-03-26 20:07:11
【问题描述】:
我正在为我们的 Android 应用程序创建一个默认主题,以指定要应用于整个应用程序的默认自定义主题。我们的想法是我们不必在布局中指定与外观相关的属性,它们应该通过将自定义主题应用于整个应用程序来自动注入。
我可以通过覆盖它们的样式来为 TextView 和 EditText 等 UI 小部件执行此操作。
例如覆盖android:textViewStyle和android:buttonStyle等。
如何对布局(LinearLayout 或 RelativeLayout 等)执行相同操作,以便为布局指定默认背景?
android manifest 中的应用程序元素如下所示:
....
<application android:icon="@drawable/ic_launcher" android:label="@string/app_title" android:allowBackup="false"
android:theme="@style/Theme.MyCustomTheme" android:name="MyAppClass">
Theme.MyCustomTheme 看起来像这样:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.MyCustomTheme" parent="Theme.AppCompat">
<item name="android:textViewStyle">@style/my_custom_text_view_style</item>
<item name="android:editTextStyle">@style/my_custom_edit_text_style</item>
<item name="android:buttonStyle">@style/my_custom_button_style</item>
<item name="android:listViewStyle">@style/my_custom_list_style</item>
上面的自定义样式继承自各自的android基础样式。
我正在寻找正确的 android 属性以在上面使用来覆盖布局的样式,以便我可以将自定义默认背景应用于布局中声明的每个布局(LinearLayout 或 RelativeLayout 等)@987654331 @ 文件,而不必在布局 xml 中明确指定它。我尝试覆盖android:colorBackground,但这没有任何区别。我尝试覆盖android:windowBackground,但这也改变了操作栏的颜色。请注意,我使用的是 appcompat 支持库中的 appcompat 主题。
【问题讨论】:
标签: android android-layout android-theme