使用getBackground().setAlpha,导致其他布局背景透明度都改变的问题
来源:互联网 发布:淘宝网退回旧版本 编辑:程序博客网 时间:2024/05/19 07:42
最近在做的项目包含了一个标题栏,可随着ScrollView滑动而改变自身透明度。使用的正是getBackground().setAlpha来实现,在Android 5.0以下版本一直没问题,但在5.0以上系统时,就会导致其他共用一个资源的布局(例如:@color/white)透明度都跟对标题栏被改变了。
原文链接
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/ll_title_bar" android:layout_width="match_parent" android:layout_height="50dp" android:background="@color/white" android:orientation="vertical" /> <LinearLayout android:id="@+id/ll_content" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="vertical" /></LinearLayout>例如,使用getBackground().setAlpha来改变ll_title_bar的透明度后,ll_content的透明度也会跟着被改变。
在网上找了资料才知道,在布局中多个控件同时使用一个资源的时候,这些控件会共用一个状态,例如ColorState,如果你改变了一个控件的状态,其他的控件都会接收到相同的通知。这时我们可以使用mutate()方法使该控件状态不定,这样不定状态的控件就不会共享自己的状态了。
titleLayout.getBackground().mutate().setAlpha(255);
原文链接
0 0
- 使用getBackground().setAlpha,导致其他布局背景透明度都改变的问题
- 使用getBackground().setAlpha,导致其他布局背景透明度都改变的问题
- 使用getBackground().setAlpha,导致其他布局背景透明度都改变的问题
- 使用getBackground().setAlpha,导致其他布局背景透明度都改变的问题
- 使用getBackground().setAlpha,导致其他布局背景透明度都改变的问题
- getBackground().setAlpha导致其他布局背景透明度都改变的问题
- getBackground().setAlpha所导致问题
- getBackground().setAlpha所导致问题
- getBackground().setAlpha所导致问题
- getBackground().setAlpha所导致问题
- getBackground().setAlpha(0)设置透明度连下层控件背景色都被改变
- getBackground().setAlpha导致所有资源都有变化
- getBackground().setAlpha 奇葩问题
- Android设置透明度导致其他布局文件颜色改变如白色变灰色问题
- android 控件 getBackground().setAlpha设置透明值,影响其他页面样式问题
- view.setAlpha()和 view.getBackground().setAlpha()的区别
- Android setAlpha使用时导致其他界面变透明解决方案
- 改变navigationBar的背景导致其他控件被覆盖
- TPC-H测试数据表生成,以及在Impala中的使用
- 15分钟帮你轻松理解 JS闭包
- cordova的白名单插件所形成的问题 Please add one when using the cordova-plugin-whitelist plugin
- 防安全漏洞开发规范
- 使用Vagrant在Windows下部署开发环境
- 使用getBackground().setAlpha,导致其他布局背景透明度都改变的问题
- 怎样写出优秀的研究论文?
- 文章标题
- OC中属性self.a与_a访问的区别
- 如何使用Android Studio把自己的Android library分享到jCenter和Maven Central
- NSTimer 倒计时
- Jedis的八种实现方式
- Android动画使用中的若干问题【持续更新】
- 【数据库】数据库负载均衡、读写分离技术