Android中的样式

来源:互联网 发布:r语言与matlab 大数据 编辑:程序博客网 时间:2024/06/11 19:21

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>
运行结果:




0 0
原创粉丝点击