- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我看到了一些 SO 问题,他们提供了一些可能的方法来实现我想要的。例如:
在styles.xml中使用colorControlHighlight
属性。
这是我的样式-v21.xml:
<style name="SelectableItemBackground">
<item name="android:colorControlHighlight">#5677FC</item>
<item name="android:background">?attr/selectableItemBackground</item>
</style>
还有我的小部件:
<TextView
android:id="@+id/tv_take_photo_as_bt"
android:layout_width="280dp"
android:layout_height="48dp"
android:text="@string/act_take_photo"
style="@style/SelectableItemBackground"/>
而且它不起作用。我也尝试将parent="Theme.AppCompat
添加到“SelectableItemBackground”样式,或者改成colorControlHighlight(no android: prefix)"
,或者改成? android:attr/selectableItemBackground
,两个都没用。
在布局中使用 backgroundTint
属性。
所以我将 android:backgroundTint="#5677FC"
添加到我的 TextView
中。还是没用。然后我尝试将 android:backgroundTintMode
改为 src_in
和 src_atop
,它们都没有任何区别。
那么,当我使用 ?attr/selectableItemBackground
作为背景时,如何更改波纹颜色。我只关注 Lollipop 及以上。提前谢谢!
最佳答案
终于找到解决办法了:与其直接在主题SelectableItemBackground
中使用android:colorControlHighlight
,不如写另一种风格:
<style name="SelectableItemTheme">
<item name="colorControlHighlight">@color/ripple_color</item>
</style>
然后:
<style name="SelectableItemBackground">
<item name="android:theme">@style/SelectableItemTheme</item>
<item name="android:background">?attr/selectableItemBackground</item>
</style>
最后将 style="@style/SelectableItemBackground"
添加到 layout.xml 中的 View
中。
2016 年 8 月 26 日更新在N发布之后,我发现有时候我们不能用这个方法来为某种View
(例如CardView
)设置波纹颜色。现在我强烈推荐开发者使用RippleDrawable
,它也可以在xml中声明。这是一个例子:
我想在用户触摸/点击API21以上的CardView
时显示涟漪效果,当然Lollipop之前应该有另一种反馈。所以我应该写:
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foreground="@drawable/selectable_item_background"/>
和drawable
文件夹中的selectable_item_background
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@android:color/transparent" />
<item android:drawable="@color/color_clicked" />
</selector>
selectable_item_background
在 drawable-v21
文件夹中:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ripple_black" />
</selector>
最后,drawable
(或drawable-v21
)文件夹中的ripple_black
:
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@color/color_clicked"
tools:ignore="NewApi" /> <!--you can remove this line if it's in v21 folder-->
就是这样。对于其他 View ,也许您应该使用 android:background="@drawable/selectable_item_background"
。不要忘记为它们设置 OnClickListener
、OnTouchListener
或类似的东西,否则不会显示波纹。
关于android - 使用 ?attr/selectableItemBackground 作为背景时如何修改波纹颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33061050/
我只是想知道下面的$(*[attr])和$([attr])中哪一个更可取。为什么? 因为两者都在做同样的事情。 $('[onclick]').each(function(i,elem){ cons
长期以来我一直在尝试找出问题所在,但不幸的是无法 如果我这样做 android.enableAapt2=true 代码工作正常,但是删除相同的(应该是强制性的)会抛出一个错误说 \incrementa
使用此代码: $('#ipadmenu section').attr('data-order', hash) 我将 data-order 属性设置为“hash”的值。如何选择具有该属性/值的元素而不是
我有一个用于扩展的组合框监听器。展开后,它会对组合框选项中具有特定类的每个元素执行一些样式设置。所需的更改之一是根据当前属性的值更改属性。使用 this 返回未定义。 expand : funct
性能上有区别吗 :not([attr="value"]) 和 [attr!="value"] ? CSS3 规范是否推荐了一种替代方案? 编辑: CSS3 规范不包含 [attr!="value"]
所以我有一个叫做 say,mySave 的指令,它几乎就是这个 app.directive('mySave', function($http) { return function(scope,
有人可以告诉我有什么区别吗 ?android:attr/colorPrimary 和 ?attr/colorPrimary 无论我使用哪个,结果都是一样的。尽管第一个选项导致android.view.
Xpath问题: 何时使用@和属性,何时不使用。有关系吗?有什么区别 最佳答案 使用//tag[attr]时,将选择所有具有至少一个名为tag的子元素的attr元素。另一方面,使用//tag[@att
android布局xml文件中的?android:attr/和?attr/有什么区别?在不同的情况下我们应该使用哪一个? 最佳答案 1。 ?attr/ 定义并引用您在应用程序中自行定义的属性的值。 2
如果 obj 不存在 obj? 生成一个 nil 所以 obj?.attr 也是。 如果 obj 为 nil,则 obj!.attr 崩溃。 但是如果我确定 obj 在代码的某个点总是存在,那么对我来
有一个这样的 HTML。 Back 1 2 3 Next 为了获得最大的页数,我写了这篇文章。 doc = Nokogiri::HTML(html) doc.xpath('//
我想知道这些标签在 android xml 中如何工作。例如在造型方面 style="?android:attr/buttonBarButtonStyle" 和 style="@android:att
这是我的代码: $("input[name=donationmode]").change(function() { $(".setpaymentOptions").children().add
我已经搜索了一段时间,但没有找到我正在搜索的内容。 事情是这样的,我有两张表,我们称它们为表 A 和 B。当 A 更新时,我需要更新 B 中的属性。例如:A. 电子邮件和 B. 电子邮件。当用户在 A
大家好,在访问一个循环的 php 变量时遇到了一个小问题。我的脚本循环使用来自 mysql 数据库的 x 和 y。它还循环出我无法访问的 id,它显示为未定义。我正在使用鼠标移开功能来检测已循环的每个
我将自己的标签转换为输入。我可以使用 select 为输入选择只读/禁用。我做到了。有用。但不是在 ie8 )). 我阅读了 Angular 和 IE8 的官方文档。我添加了它。但是我的应用程序在 i
我正在使用令人惊叹的 attrs 库以一种非常优雅的方式定义许多对象属性,到目前为止它一直运行得非常棒。 我目前遇到的唯一问题是,有时我想通过引用其他 attr.ib() 属性来定义默认值。如果 na
我注意到 javascript 有几种方法来设置和获取元素的属性。 我不确定它们之间有什么区别。特别是,是否存在跨浏览器问题。 最佳答案 DOM 元素的特性和属性有很大不同,这种差异是一些混淆的根源。
在 4.x 设备上,使用 ?android:attr/selectableItemBackgroundBorderless 的布局文件会导致崩溃,但 ?attr/selectableItemBackg
.attr('disabled', 'disabled') 和 .attr('disabled', true) 在我的代码中都有效,但我只是想知道:两者中哪一个更有效和/或哪一个更常用?真的有区别吗?
我是一名优秀的程序员,十分优秀!