Android中的樣式

Android中可以自定義樣式style,在佈局文件中可以引用我們自定義的style。

在style.xml文件中自定義樣式:

 <style name="myStyle">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">0dp</item>
        <item name="android:layout_weight">1</item>
        <item name="android:padding">10dp</item>
        <item name="android:background">#f00</item>
        <item name="android:src">@drawable/bd_logo1</item>
        <item name="android:layout_marginTop">5dp</item>
    </style>
在activity_main.xml中引用我們自定義的style:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp" >

	<ImageView 
	    style="@style/myStyle"/>  
	<ImageView 
	    style="@style/myStyle"/>  
	<ImageView 
	    style="@style/myStyle"/>  

</LinearLayout>
運行結果:




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章