這篇文章給大家介紹怎么對Android應用的背景透明度進行設置,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
實現代碼:
public void button01(View view){
// search透明度不起作用
title.setAlpha(0.2f);
search.setAlpha(0.8f);
}
public void button02(View view){
// 在布局中多個控件同時使用一個資源的時候,這些控件會共用一個狀態
// 如果你改變了一個控件的狀態,其他的控件都會接收到相同的通知
title.getBackground().setAlpha(51);
search.getBackground().setAlpha(153);
}
public void button03(View view){
// 使用mutate()方法使該控件狀態不定,這樣不定狀態的控件就不會共享自己的狀態了
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>
關于怎么對Android應用的背景透明度進行設置就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。