您的位置:首页 > 移动开发 > Android开发

android设置控件背景透明、半透明的方法

2016-05-21 17:38 736 查看
方法1(透明):

在布局文件的控件中设置background的属性为@null

例如:

<Button

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:background="@null" />

方法2(透明):

在布局文件的控件中设置background的属性为@android:color/transparent

例如:

<Button

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:background="@android:color/transparent" />

方法3(半透明):

在activity中找到控件,并设置setAlpha()的值

例如:

Button button = (Button)findViewById(R.id.button);

button.getBackground().setAlpha(50);

注:在布局文件中必须要设置控件的background属性

setAlpha的值为0~255之间,设置半透明
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: