温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么对Android应用的背景透明度进行设置

发布时间:2020-12-07 15:37:26 来源:亿速云 阅读:249 作者:Leah 栏目:移动开发

这篇文章给大家介绍怎么对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); 
 } 

布局:

<&#63;xml version="1.0" encoding="utf-8"&#63;> 
<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

<&#63;xml version="1.0" encoding="utf-8"&#63;> 
<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应用的背景透明度进行设置就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI