在安卓棒棒糖系统上,我正在使用:
android:background="?android:attr/selectableItemBackground"
当我点击按钮时,希望材料动画有所反应。
当按钮位于白色或浅色背景中(例如CardView)时,它可以正常工作。
但是当我想在深色背景上使用相同的效果时,我们几乎看不到它的效果,因为不够明显。
有人有什么想法吗?
谢谢
在安卓棒棒糖系统上,我正在使用:
android:background="?android:attr/selectableItemBackground"
当我点击按钮时,希望材料动画有所反应。
当按钮位于白色或浅色背景中(例如CardView)时,它可以正常工作。
但是当我想在深色背景上使用相同的效果时,我们几乎看不到它的效果,因为不够明显。
有人有什么想法吗?
谢谢
在API 21+上,您可以在View
或ViewGroup
上设置android:theme="@android:style/ThemeOverlay.Material.Dark"
,以将所有主题属性(文本颜色、涟漪颜色、按钮颜色等)更改为“暗”版本。如果您将其设置在ViewGroup
上,则该主题也会应用于充气期间的所有子元素。这是在否则为“浅”接口中拥有“深色”区域的简便方法(反之亦然)。
<LinearLayout
android:id="@id/my_dark_layout"
...
android:theme="@android:style/ThemeOverlay.Material.Dark">
<TextView
android:id="@id/my_dark_bounded_ripple"
...
android:background="?android:attr/selectableItemBackground"
android:text="Bounded ripple" />
<ImageButton
android:id="@id/my_dark_unbounded_ripple"
...
android:background="?android:attr/selectableItemBackgroundBorderless"
android:src="@drawable/my_icon" />
</LinearLayout>
style =“@ style / Widget.AppCompat.Button.Borderless”
和android:background =“?selectableItemBackgroundBorderless”
,它就无法正常工作。您知道原因吗? - deadfishapplication
标签中设置的theme
属性,即使它们不是Activity的一部分(屏幕叠加)。但我猜这只是另一个Google的东西。 - TheWanderer使用AppCompat的解决方案(也适用于旧API)
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
android:background="?attr/selectableItemBackground"
改变应用程序主题的另一种方法是:
Theme.AppCompat.NoActionBar
对我来说它运行良好。