【发布时间】:2012-09-26 03:45:25
【问题描述】:
我无法将自定义方案(样式)应用于某些视图。我在 res/values/styles.xml 中定义了自己的风格
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="myStyle1">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/red</item>
<item name="android:textColorHighlight">@color/blue</item>
<item name="android:textColorHint"> @color/fuchsia</item>
<item name="android:textColorLink">@color/olive</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme" parent="android:Theme.Light" />
</resources>
我已将此样式应用于我的简单测试应用程序的主要活动,如下所示
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/myStyle1" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.
.
.
</application>
MainActivity 的布局包含几个按钮,一些 textView,其中一些明确指定了 style 属性,其他应该从整个 Activity 继承它。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/silver"
android:orientation="vertical" >
<EditText android:id="@+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:hint="@string/edit_message" />
<Button android:id="@+id/send_button"
style="@style/myStyle1"
android:text="@string/button_send" />
<Button android:id="@+id/relative_activity"
android:text="@string/rel_activitity_text"
android:onClick="startRelativeActivity"/>
<Button android:id="@+id/button_TTT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textColor="@color/red"
android:text="@string/button_TTT" />
<fragment android:name="my.firstapp.Fragment1"
android:background="@color/red"
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
据我所知,活动中的所有内容都应该根据我定义的样式进行风格化,但是,这就是我得到的
如您所见,只有具有指定样式的按钮的文本为红色,其他两个没有。然而,即使是白色按钮也能从该方案中获得正确的字体,因此至少有一部分正在被应用。为什么不是全部?任何帮助将不胜感激,我非常困惑。
【问题讨论】:
标签: android android-layout button android-styles