国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android 背景透明度設(shè)置總結(jié)

2019-12-12 02:41:20
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

一、寫在前面的

在需求上遇到背景設(shè)置透明度還是比較常見(jiàn)的,設(shè)置透明度有幾種方式,但是不同的場(chǎng)景應(yīng)用下,不同的方式可能會(huì)出現(xiàn)一些問(wèn)題。針對(duì)開(kāi)發(fā)過(guò)程中的需求做以下總結(jié)。

二、先看效果圖

圖1、

   

圖2、


圖3、

 

圖4

介紹:圖1、藍(lán)色頭部和輸入框背景初始狀態(tài)

   圖2、點(diǎn)擊按鈕01,輸入框的透明度不起作用,和title的透明度一樣

   圖3、點(diǎn)擊按鈕02,背景透明度設(shè)置正常,但是可能會(huì)對(duì)全局的背景有影響

   圖4、點(diǎn)擊按鈕03,背景透明度設(shè)置正常,具體原因代碼注釋有提到

三、再加上代碼

按鈕點(diǎn)擊

public void button01(View view){   // search透明度不起作用   title.setAlpha(0.2f);   search.setAlpha(0.8f);  }  public void button02(View view){   // 在布局中多個(gè)控件同時(shí)使用一個(gè)資源的時(shí)候,這些控件會(huì)共用一個(gè)狀態(tài)   // 如果你改變了一個(gè)控件的狀態(tài),其他的控件都會(huì)接收到相同的通知   title.getBackground().setAlpha(51);   search.getBackground().setAlpha(153);  }  public void button03(View view){   // 使用mutate()方法使該控件狀態(tài)不定,這樣不定狀態(tài)的控件就不會(huì)共享自己的狀態(tài)了   title.getBackground().mutate().setAlpha(51);   search.getBackground().mutate().setAlpha(153);  } 

布局:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent">  <LinearLayout   android:id="@+id/ll_title"   android:layout_width="match_parent"   android:layout_height="80dp"   android:gravity="center"   android:background="#0000ff"   android:orientation="horizontal">   <EditText    android:id="@+id/et_search"    android:layout_width="200dp"    android:layout_height="60dp"    android:gravity="center"    android:hint="輸入框"    android:textColorHint="#ffffff"    android:background="@drawable/search_title_bg"/>  </LinearLayout>  <LinearLayout   android:layout_width="match_parent"   android:layout_height="wrap_content"   android:layout_marginTop="40dp"   android:orientation="horizontal">   <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="01"    android:onClick="button01"/>   <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="02"    android:onClick="button02"/>   <Button    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="03"    android:onClick="button03"/>  </LinearLayout> </LinearLayout> 

輸入框背景 search_title_bg

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="rectangle">  <solid   android:color="#000000"/>  <corners   android:radius="8dp"/>  <stroke   android:width="1dp"   android:color="#666666"/> </shape> 

四、寫在后面的

背景透明度設(shè)置比較常見(jiàn),mutate()方法,可以解決背景透明狀態(tài)設(shè)置異常的現(xiàn)象。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 江油市| 武清区| 美姑县| 利津县| 桂阳县| 攀枝花市| 金溪县| 铜山县| 武宁县| 吐鲁番市| 河津市| 苏尼特左旗| 鄄城县| 余干县| 寻乌县| 镇沅| 昌乐县| 拉萨市| 镇远县| 隆尧县| 宽甸| 唐河县| 新干县| 上虞市| 西平县| 英吉沙县| 庆阳市| 宁城县| 壤塘县| 乐平市| 新安县| 湘西| 汉川市| 桐柏县| 山丹县| 和田县| 厦门市| 云林县| 湖口县| 银川市| 井冈山市|