设置一个主题为Android的所有editTexts主题、Android、editTexts

2023-09-07 15:04:34 作者:对你何止一句很在乎

我已经完成使我的应用程序。现在,我要重新设置所有我editTexts,以使布局宽度填充母,而不是包的内容。

I have finished making my app. Now, I want to reset all my editTexts to have the layout width as fill parent instead of wrap content.

android:layout_width="fill_parent"

而目前我所有的editTexts是

while currently all my editTexts are

android:layout_width="wrap_content"

有没有什么办法可以在样式XML文件中的每个布局做到这一点,而不是单独? 我现在有这是我的styles.xml

Is there any way i can do this in a style xml file, instead of individually in each layout? I currently have this as my styles.xml

<style name="AppTheme" parent="android:Theme.Light">  
    <item name="android:fontFamily">Verdana</item>
    <item name="android:editTextStyle">@style/EditTextStyle</item>
</style>

<style name="EditTextStyle" parent="@android:style/Widget.EditText">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:textColor">#808080</item>
</style>

但我发现一个异常说layout_width必须指定。 这是我的例外:

But i'm getting an exception saying that layout_width must be specified. This is my exception:

07-15 11:13:34.872: E/AndroidRuntime(1195): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.passwordkeeper.ui/com.passwordkeeper.ui.ActivityLogin}: java.lang.RuntimeException: Binary XML file line #29: You must supply a layout_width attribute.

任何讨巧还是我必须改变所有的属性我EDITTEXT的分别?

Any easy way out or do i have to change the attribute in all my editText's individually?

谢谢!

推荐答案

您可以试试这个。 下面是你需要改变调用自定义主题清单文件的部分(这里叫做自定义主题是AppTheme:

You can try this one. Here is the part of the manifest file you need to change to call your custom theme (the custom theme called here is AppTheme:

<application android:name="YourApplication"
android:theme="@style/AppTheme" >

然后在你的文件styles.xml,创建和定制这个自定义主题:

Then in your file styles.xml, create and customize this custom theme:

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
 <item name="android:typeface">YourTypeFace</item>
</style>

您可以添加你需要的样式里面的参数。这将样式应用到所有的textviews。

You can add the parameters you need inside the style. This will apply the style to all your textviews.

 
精彩推荐