我试图让所有的EditText
的在我的应用程序有一个一致的外观。我知道,我可以做这样的事情:
I'm trying to make all EditText
's in my application have a consistent look. I'm aware that I can do something like this:
<style name="App_EditTextStyle">
<item name="android:background">@drawable/filled_roundededges_box_dark</item>
<item name="android:textColor">#808080</item>
<item name="android:layout_height">45dip</item>
</style>
然后,我可以做一个特定的的EditText
通过这样做,有这样的风格:
Then I can make a particular EditText
have this style by doing this:
<EditText ...
style="@style/App_EditTextStyle
...>
不过,这样一来我记得要单独设置样式为每个的EditText
在我的应用程序,它是乏味的,如果不容易出错。
But this way I have to remember to set the style individually for each and every EditText
in my application which is tedious, if not error prone.
有没有一些方法,我能做出这样一个主题或东西的一部分吗?这让我没有这种风格关联到每个的EditText
。事情是这样的虚构code座:
Is there some way I could make this a part of a theme or something? This is so I don't have to associate this style to every EditText
. Something like this fictitious code block:
<style name="App_Theme" parent="@android:style/Theme.Holo">
...
<item name="android:EditTextSyle">@style/App_EditTextStyle</item>
...
<style>
然后在我的的AndroidManifest.xml
我是这样的:
<application
....
android:theme="@style/App_Theme">
和瞧!我所有的的EditText
的有一贯的风格有没有我指定的样式为每个实例。
And Voila! all my EditText
's have the consistent style without me having to specify the style for each instance.
重写属性指向的EditText
风格(名为 editTextStyle
:))在你的自定义主题:
Override the attribute pointing to the EditText
style(named editTextStyle
:) ) in your custom theme:
<style name="App_Theme" parent="@android:style/Theme.Holo">
<item name="android:editTextStyle">@style/App_EditTextStyle</item>
</style>
,使您的自定义样式,延长 Widget.EditText :
<style name="App_EditTextStyle" parent="@android:style/Widget.EditText">
<item name="android:background">@drawable/filled_roundededges_box_dark</item>
<item name="android:textColor">#808080</item>
<item name="android:layout_height">45dip</item>
</style>