日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

android Style(样式)的解析

發布時間:2023/11/27 生活经验 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android Style(样式)的解析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先說下為啥要使用樣式吧,舉個例子來說吧

當要做這樣的一個布局的時候


每個標簽都要寫的話,會感覺怎樣

<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:orientation="horizontal" ><Buttonandroid:id="@+id/bt1"android:layout_width="match_parent"android:layout_height="35sp"android:layout_marginLeft="6dp"android:layout_marginRight="10dp"android:layout_weight="1"android:background="#009999"android:text="上班族"android:textColor="#ffffff"android:textSize="11sp" /><Buttonandroid:id="@+id/bt2"android:layout_width="match_parent"android:layout_height="35sp"android:layout_marginRight="10dp"android:layout_weight="1"android:background="#009999"android:text="醫療"android:textColor="#ffffff"android:textSize="11sp" /><Buttonandroid:id="@+id/bt3"android:layout_width="match_parent"android:layout_height="35sp"android:layout_marginRight="10dp"android:layout_weight="1"android:background="#009999"android:text="媒體"android:textColor="#ffffff"android:textSize="11sp" /><Buttonandroid:id="@+id/bt4"android:layout_width="match_parent"android:layout_height="35sp"android:layout_marginRight="6dp"android:layout_weight="1"android:background="#009999"android:text="白領"android:textColor="#ffffff"android:textSize="11sp" /></LinearLayout>

要寫很多這樣的,不停的重復寫是不是很煩呢,為了方便我們 要學習樣式了,

樣式資源

首先要明白樣式資源是用來干啥的,

樣式資源主要用于對組件的顯示樣式經行控制,改變文本框顯示文字的大小和顏色

位置:

res/values 目錄中,

它的根元素是<resources></resources>標記,

在該元素中,使用<style></style>標記定義樣式,

做的時候到values下找到styles


我把上面的代碼簡化下


這個就是要在xml中寫的提前用style寫好這樣在

xml中不用寫了

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:orientation="horizontal" ><Buttonandroid:id="@+id/bt1"style="@style/button"android:layout_marginLeft="10dp"android:text="上班族" /><Buttonandroid:id="@+id/bt2"style="@style/button"android:text="醫療" /><Buttonandroid:id="@+id/bt3"style="@style/button"android:text="媒體" /><Buttonandroid:id="@+id/bt4"style="@style/button"android:text="白領" /></LinearLayout>   
它的效果圖


這樣是不是很方便了,樣式的好處就是一次寫好多出都能調用

下面的標簽也是能調用的?


總結

以上是生活随笔為你收集整理的android Style(样式)的解析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。