欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 背景透明度設置總結

 更新時間:2017年06月13日 11:36:04   作者:ZPan_  
這篇文章主要介紹了Android 背景透明度設置總結,本文通過實例代碼給大家介紹的非常詳細,感興趣的的朋友參考下吧

一、寫在前面的

在需求上遇到背景設置透明度還是比較常見的,設置透明度有幾種方式,但是不同的場景應用下,不同的方式可能會出現(xiàn)一些問題。針對開發(fā)過程中的需求做以下總結。

二、先看效果圖

圖1、

   

圖2、


圖3、

 

圖4

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

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

   圖3、點擊按鈕02,背景透明度設置正常,但是可能會對全局的背景有影響

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

三、再加上代碼

按鈕點擊

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

四、寫在后面的

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

相關文章

  • Android實現(xiàn)圓線按鈕進度效果

    Android實現(xiàn)圓線按鈕進度效果

    這篇文章主要為大家詳細介紹了Android實現(xiàn)圓線按鈕帶進度,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • Kotlin類型系統(tǒng)竟如此簡單

    Kotlin類型系統(tǒng)竟如此簡單

    這篇文章主要給大家介紹了關于Kotlin類型系統(tǒng)的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Kotlin具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-09-09
  • Android自定義view Path 的高級用法之搜索按鈕動畫

    Android自定義view Path 的高級用法之搜索按鈕動畫

    這篇文章主要介紹了Android自定義view Path 的高級用法之搜索按鈕動畫,需要的朋友可以參考下
    2017-06-06
  • Android實現(xiàn)水波紋擴散效果的實例代碼

    Android實現(xiàn)水波紋擴散效果的實例代碼

    這篇文章主要介紹了Android實現(xiàn)水波紋擴散效果的實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • Android Gradle開發(fā)指南詳解

    Android Gradle開發(fā)指南詳解

    這篇文章主要為大家詳細介紹了Android Gradle開發(fā)指南的相關資料,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • Android BitmapUtils工具類使用詳解

    Android BitmapUtils工具類使用詳解

    這篇文章主要為大家詳細介紹了Android BitmapUtils工具類的使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • Android利用FlexboxLayout輕松實現(xiàn)流動布局

    Android利用FlexboxLayout輕松實現(xiàn)流動布局

    flexbox是屬于CSS的一種布局方案,可以簡單、完整、響應式的實現(xiàn)各種頁面布局。谷歌將其引入以提高復雜布局的能力。下面這篇文章主要給大家介紹了在Android中利用FlexboxLayout輕松實現(xiàn)流動布局的相關資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-04-04
  • Android activity實現(xiàn)延時跳轉功能

    Android activity實現(xiàn)延時跳轉功能

    Activity是一個Android的應用組件,它提供屏幕進行交互。今天通過本文給大家介紹Android activity實現(xiàn)延時跳轉功能,感興趣的朋友一起看看吧
    2021-06-06
  • android應用實現(xiàn)開機自動啟動方法

    android應用實現(xiàn)開機自動啟動方法

    這篇文章主要介紹了android應用實現(xiàn)開機自動啟動方法,本文講解了原理和編碼實例,需要的朋友可以參考下
    2015-05-05
  • Flutter狀態(tài)管理Bloc之定時器示例

    Flutter狀態(tài)管理Bloc之定時器示例

    這篇文章主要為大家詳細介紹了Flutter狀態(tài)管理Bloc之定時器示例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03

最新評論