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之间,设置半透明
在布局文件的控件中设置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之间,设置半透明
相关文章推荐
- android之子线程中的Toast
- Android Studio使用lambda
- Android概述
- Android开发艺术探索—— 第十一章Android的线程和线程池
- Android listview子控件的的点击事件
- android图片加载与缓存
- android中的AIDL
- Mac、Windows下Android Studio快捷键的使用
- 给 Android 开发者的 RxJava 详解
- ViewHolder重用机制 RecyclerView+CardView 优化
- android反编译工具Apktool安装与使用
- 给 Android 开发者的 RxJava 详解
- android模拟器无法使用camera拍照
- Android SDK 在线更新镜像服务器资源
- Android使用 DrawerLayout实现侧滑
- Android自定义ViewPager指示器
- android studio <item/>标签下不能使用showAsAction属性
- Android studio 使用JitPack发布library到Github开源库
- 仿网易云音乐Android端歌手资料页面的实现
- android调试输出log打印信息到本地文件