問題描述
我正在嘗試更改 EditText 的樣式?有可能實現嗎?如果是這樣,我會很高興被告知,否則還有其他可用的方法.
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.
推薦答案
您可以使用為任何小部件定義的屬性 style="@style/your_style"
.
You can use the attribute style="@style/your_style"
that is defined for any widget.
要定義您的樣式,您必須在 values 文件夾中創建一個名為 style.xml
的文件(即
esvaluesstyles.xml
)并使用以下內容語法:
To define your style you have to create a file called style.xml
in the values folder (i.e.
esvaluesstyles.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>
屬性 parent="@android:style/Widget.EditText"
很重要,因為它將確保定義的樣式擴展了基本的 Android 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.
這篇關于android:如何更改編輯文本的樣式?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!