- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我最近将我的手机更新为 Android Marshmallow 并在其上运行了我现有的应用程序,但注意到颜色行为有所不同:将更改应用到 View (可绘制)的背景时,共享相同背景的所有 View (引用)也将应用相同的更改。而以前,情况并非如此。
例子
在此示例中,我有两个具有相同背景颜色的 View ,我想更改其中一个 View 的 alpha 级别。
首先我们定义布局中的 View :
<LinearLayout
android:id="@+id/test1"
android:orientation="horizontal"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@color/testColor2">
</LinearLayout>
<LinearLayout
android:id="@+id/test2"
android:orientation="horizontal"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@color/testColor1"
android:layout_marginLeft="5dp">
</LinearLayout>
两个 View 共享相同的背景颜色或可绘制对象:
<color name="testColor1">#3F51B5</color>
<color name="testColor2">#3F51B5</color>
现在我们要改变两个背景之一,像这样:
LinearLayout test1 = (LinearLayout) findViewById(R.id.test1);
LinearLayout test2 = (LinearLayout) findViewById(R.id.test2);
test1.getBackground().setAlpha(80);
下载示例项目
here.
几点思考:
问题
如何在不影响共享相同背景的其他 View 的情况下更改 View 的背景。
最好仍然能够使用直接引用颜色 xml 文件中定义的颜色的背景
最佳答案
Most likely the class of each view's background and constantstate arethe same object. It seems as if the two color resources have been"merged" somewhere -- meaning they have shared ConstantState. Maybe inthe Resources class' caching? I would've expected them to stayseparate since they're different resources (albeit with the same colorvalue), but apparently not.
ColorDrawable 的状态存储 alpha,因此对其中一个的任何更改都会更改其他。为防止这种情况发生,您可以先在可绘制对象上调用 mutate(),将两个可绘制对象分开(通过复制状态)。
在示例中,这将导致使用 test1.getBackground().mutate().setAlpha(80);
而不是直接应用 alpha。
关于android - 颜色/可绘制更改应用于具有相同背景(颜色)的所有 View [Marshmallow],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33354788/
概览 我正在使用 Flask-SqlAlchemy,现在我正在研究 marshmallow 来帮助我序列化和反序列化请求数据。 我能够成功: 使用 Flask-SqlAlchemy 创建我的模型 使用
我最近更新了我的应用程序以支持 android 6 marshmallow。我按照 https://developer.android.com/training/permissions/request
我正在尝试将 marshmallow-dataclass 与 marshmallow-oneofschema 结合起来以处理提供给我并用于连接 java 和 python 应用程序的数据结构。 在 J
marshmallow.Schema (v3.0+) 之间是否有区别,其中名称为 foo 的字段是使用 attribute="bar"< 定义的,另一个名称为 bar 的字段是用 data_key="
有没有办法在使用 Marshmallow - sqlalchemy 时避免将数据插入 session sqlalchemy marshmallow 避免加载到 session 中 引用:https:/
我想知道如何序列化嵌套Schema的字典。 天真地,我希望这样的语法能够工作: fields.List(Schema) fields.Dict(Schema) 或者也许 fields.List(fie
我需要创建一个与给定规范一致的棉花糖模式,其中我无法更改键名称。其中一个关键是 Python 中的保留关键字“from”。 class TemporalExtentSchema(Schema):
我正在使用 marshmallow 来验证 API 的数据。但是,它不适用于必填字段。 以下代码适用于长度验证。 password = fields.String(validate = validat
我正在为我的应用程序添加某些权限,例如允许访问相机,并且一切正常。但是当我最小化应用程序并禁用权限然后打开应用程序时,应用程序崩溃而不要求我重新启用权限(直到我关闭应用程序然后打开它)。我该如何修复此
我使用的是 nexus 6 android 6.0,仅针对 WRITE_EXTERNAL_STORAGE 权限对话框未显示,因为它正在显示其他危险权限。 final private int REQUE
我的 SMS 应用程序使用了一些危险的权限,例如发送 SMS、阅读联系人 等,我正在尝试为 android 6.0 测试新的权限系统但是当我在 Android 6.0 设备上安装它时,它已经授予这些权
我为 Marshmallow 设备集成了 READ PHONE STATE 的 Android Runtime Permission。此实现工作正常,弹出窗口显示在我的应用程序中,带有允许/拒绝选项。
我有这段代码允许用户访问相机拍照并从图库中选择图像,它适用于我运行 Android 5.1.1 的索尼 Xperia Z3。 我现在已经升级到运行 Android 6.0 的 Nexus 5X,但是当
您好,我想添加一个全局文本选择监听器,它显示任何选定文本的子菜单。 Android 6 通过新的文本选择监听器允许这样做。 是否可以通过外部应用程序使用此功能,然后填充子菜单? 最佳答案 这个概念被称
我希望开始使用 Marshmallow Fingerprint Authentication API。我明白要请求许可,我必须使用以下方法: ContextCompat.checkSelfPermis
我正在尝试像这样自定义我的搜索栏: 在 API 级别 我的style.xml: @drawable
在 Android Marshmallow 中有什么方法可以检测权限状态变化吗? 我还没有看到广播... 最佳答案 权限不能在应用程序中间更改。如果更改了权限 -> 应用程序将重新启动。没有广播 -
我在我们的团队中遇到了这个问题:我们想测试与日历的交互,显然我们需要日历写入权限才能执行此操作。有没有办法确保为仪器测试提供必要的权限?我知道您实际上可以授予对特定 avd 的权限,但是有更好的方法吗
我正在使用分析并在编译时收到此混淆警告: Warning: com.google.android.gms.internal.zzw$zza: can't find superclass or inte
RUN-TIME Permission 这样一个新的很棒的安全功能 我试图理解它并为此制作一个演示但是我想到了一个问题,即当我使用 DIALOG 处理用户权限时。 如何处理“不再询问” 假设我的应用程
我是一名优秀的程序员,十分优秀!