【发布时间】:2014-08-01 13:50:51
【问题描述】:
我一直未能让我的应用看起来“不错”。上一篇关于该主题的帖子链接到一个非常好的网站,解释如何创建单个样式文件,用我自己的例如有效地覆盖默认主题元素。将基本的“按钮”设置为绿色背景,而不必为每个单独的按钮使用“样式”或“背景”属性。
我已尝试实现此功能,但似乎无法正常工作 - 这就是我在清单中的内容:
android:theme="@style/spyEyeTheme" >
这是单个文件:
<style name="spyEyeTheme" parent="android:Theme.Light">
<item name="android:buttonStyle">@style/myButton</item>
<item name="android:textViewStyle">@style/myTextView</item>
<item name="android:editTextStyle">@style/myEditText</item>
</style>
<style name="myTextView" parent="android:Theme.Light">
<item name="android:textColor">#FF0000</item>
<item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="myEditText" parent="android:Theme.Light">
<item name="android:textColor">#FFFFFF</item>
<!-- item name="android:textSize">30sp</item> -->
<item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@color/lime</item>
</style>
<style name="myButton" parent="android:Theme.Light">
<item name="android:background">#008000</item> <--- green background for button
</style>
理论上,如果我现在在 XML 文件中定义一个按钮,它应该会生成一个带有绿色背景的按钮:
<Button
android:id="@+id/loadBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/newBtn"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:onClick="loadGame"
android:text="@string/load"
android:textSize="30sp"
android:typeface="sans" />
不幸的是,事实并非如此。没有错误,但按钮以标准灰色背景显示(其他属性也不起作用)。好像系统找不到或忽略了我的样式重定向。
有什么想法吗?
编辑:好的,让它工作但不知道为什么。在 Eclipse 中,在我的 XML 文件的“图形布局”选项卡上,我注意到屏幕顶部有一个下拉列表,其中显示了“AppTheme”。下拉菜单中有一个选项可以更改为我的“spyEyeTheme”,我这样做了,现在它正在工作。
但是,我看不到我的代码有任何更改 - 谁能解释发生了什么?
【问题讨论】:
-
您是否将此主题应用于 AndroidManifest 文件中的应用程序或活动?如果用于应用程序,请确保您不要在活动声明中使用其他样式覆盖
-
在应用程序中,我没有在其他任何地方设置它。
标签: android xml styles manifest