风格不适用

时间:2015-04-17 18:42:41

标签: android android-edittext styles toolbar

我一直在尝试将样式应用于EditText和工具栏,它似乎无法正常工作,这是第一次发生在我身上,这是我的样式代码:

<resources>

<style name="WifiHome" parent="@style/Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@color/light_blue</item>
    <item name="android:textAppearance">@style/WifiHomeTextAppearance</item>
    <item name="android:textViewStyle">@style/MyTextViewStyle</item>
    <item name="android:textColor">@color/dark_blue</item>
</style>

<style name="WifiHomeBarStyle" parent="@style/Widget.AppCompat.Toolbar">
    <item name="android:background">@color/dark_blue</item>
    <item name="colorControlNormal">@color/white</item>
    <item name="colorControlActivated">@color/white</item>
    <item name="colorControlHighlight">@color/white</item>
    <item name="background">@color/dark_blue</item>
</style>

<style name="EditTextStyle" parent="@style/Widget.AppCompat.EditText">
    <item name="colorControlNormal">@color/dark_blue</item>
    <item name="colorControlActivated">@color/dark_blue</item>
    <item name="colorControlHighlight">@color/dark_blue</item>
</style>

<style name="MyTextViewStyle" parent="android:Widget.TextView">
    <item name="android:textAppearance">@style/WifiHomeTextAppearance</item>
</style>

<style name="WifiHomeTextAppearance" parent="@android:style/TextAppearance.Medium">
    <item name="android:textColor">@color/dark_blue</item>
    <item name="android:textSize">15dp</item>
</style>

<style name="WifiHomeTextAppearance.Large" parent="@style/WifiHomeTextAppearance">
    <item name="android:textSize">18dp</item>
    <item name="android:textStyle">bold</item>
</style>

这里是EditText的声明:

    <EditText
    style="@style/EditTextStyle"
    android:id="@+id/txtPass"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:layout_marginTop="@dimen/activity_vertical_margin"
    android:layout_marginLeft="@dimen/activity_horizontal_margin"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    android:textColor="@color/dark_blue"
    android:layout_below="@id/lblPass"/>

工具栏的声明:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/WifiHomeBarStyle"
android:id="@+id/app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/dark_blue"
android:minHeight="?attr/actionBarSize" />

简单地说它不起作用,没有效果。

1 个答案:

答案 0 :(得分:2)

尝试更改您的代码,

 <style name="WifiHome" parent="@style/Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@color/light_blue</item>
    <item name="android:textAppearance">@style/WifiHomeTextAppearance</item>
    <item name="android:textViewStyle">@style/MyTextViewStyle</item>
    <item name="android:textColor">@color/dark_blue</item>
    <item name="colorControlNormal">@color/dark_blue</item>
    <item name="colorControlActivated">@color/dark_blue</item>
    <item name="colorControlHighlight">@color/dark_blue</item>
 </style>

或者你的EditText定义中的类似内容,

 style="@style/Widget.AppCompat.EditText