android 常用 style,Android中 Styles和Themes
部分內容摘自:
http://blog.csdn.net/woshishushangdezhu/article/details/4602597
1.什么是Style,什么是Theme?
1)
Style:是一個包含一種或者多種格式化屬性的集合,我們可以將其作為一個單位用在布局XML單個元素當中。
2)
Theme:是一個包含一種或者多種格式化屬性的集合,我們可以將其作為一個單位用在應用中所有的Activity當中或者應用中的某個Activity當 中。
2.?定義Styles和Themes資源
Styles和Themes都是資源,存放在res/values文件夾下。
對每一個Styles和Themes,給
1) 自定義一個style
在res/values/sytles.xml中添加自定義的style:
flagNoExtractUi|flagNoFullscreen
18sp
#EC9237
那如何應用這個style呢?
style="@style/EditTextStyle"
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:gravity=”center_vertical|center_horizontal”
android:text=”moandroid”/>上面這個EditText的樣式,顯示輸入法的時候就不會全屏顯示而擋住輸入的內容。
2)自定義一個Theme
Theme依然在
定義Theme的一個例子
<?xml version=”1.0″ encoding=”UTF-8″?>
true
14sp
#FFFF0000
@ 表明我們應用的資源是前邊定義過的(或者在前一個項目中或者在Android 框架中)。
?表明我們引用的資源的值在當前的主題當中定義過。
在程序中使用Theme的方法
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.NewTheme);
setContentView(R.layout.main);
}
在AndroidManifest.xml中應用Theme
為了在當前所有的Activity當中使用Theme,可以打開AndroidManifest.xml 文件,編輯標簽,讓其包含android:theme屬性,值是一個主題的名字,例如:。
如果只是想讓程序當中的某個Activity擁有這個Theme,那么可以修改標簽。Android中提供了幾種內置的資源,有好幾種Theme你可以切換而不用自己寫。比如可以用對話框Theme來讓你的Activity看起來像一個對話框。在manifest中定義,例如:
如果喜歡一個Theme,但是想做一些輕微的改變,只需要將這個Theme添加為parent。Android SDK為我們提供了很多現成的Them。
3. 開發中常用的style屬性
@style/Button.Light
@style/CheckBox.Light
@style/GridView.Light
@style/ListView.Light
@style/TextView.Light
@style/Spinner.Light
@style/RadioButton.Light
@style/EditText.Light
@style/AutoCompleteTextView.Light
@style/ProgressBar.Light
@style/SpinnerDropDownItem.Light
@android:color/transparent
@drawable/scrollbar_horizontal
@drawable/scrollbar_vertical
@style/ProgressBar.Horizontal.Light
@null
true
@null
true
@null
@null
true
總結
以上是生活随笔為你收集整理的android 常用 style,Android中 Styles和Themes的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 7 蓝牙版本,[Andr
- 下一篇: 顺丰也在搞房地产 而且相关子公司已经上市