Android的:如何改变编辑文本的样式?样式、文本、编辑、Android

2023-09-12 08:04:44 作者:孑然一身

我试图改变的EditText的风格?是否有可能实现这一目标?如果是的话,我会AP preciate被告知这件事,否则有什么可供选择的方法是可用的。

I'm trying to change the style of the EditText? Is it possible to achieve that? If so I'll appreciate being told about it, otherwise what alternative ways are available.

推荐答案

您可以使用属性风格=@风格/ your_style而定义的任何部件。

You can use the attribute style="@style/your_style" that is defined for any widget.

要定义你的风格,你必须创建 style.xml 中的值文件夹称为文件(即 \水库\值\ styles.xml ),并使用以下语法:

To define your style you have to create a file called style.xml in the values folder (i.e. \res\values\styles.xml) and use the following syntax:

<style name="You.EditText.Style" parent="@android:style/Widget.EditText">
    <item name="android:textColor">@color/your_color</item>
    <item name="android:gravity">center</item>
</style>

属性父=@安卓风格/ Widget.EditText,因为这将确保所定义的样式扩展了基本的Andr​​oid 的EditText 风格,从默认的样式不同因此只属性需要加以界定。

The attribute parent="@android:style/Widget.EditText" is important because it will ensure that the style being defined extends the basic Android EditText style, thus only properties different from the default style need to be defined.