[英]How to make a CardView have a clickable&checkable effect, and how to make it dark themed?
Before CardView was introduced, I made some selectors on my app to mimic cards, and let the user also choose which theme to use for the app (some prefer a dark theme) :在 CardView 被引入之前,我在我的应用程序上做了一些选择器来模仿卡片,并让用户也选择应用程序使用哪个主题(有些人更喜欢深色主题):
I wanted to make it look&work more natively, so I tried using CardView.我想让它看起来和工作更原生,所以我尝试使用 CardView。
Sadly, I fail to understand how to set the CardView have a clickable&checkable effect (the native one of each platform, maybe with a different color), and also have the ability to set it a dark theme.遗憾的是,我不明白如何设置 CardView 具有可点击和可检查的效果(每个平台的原生效果,可能具有不同的颜色),并且还能够将其设置为深色主题。
How do I make a CardView have a clickable effect?如何使 CardView 具有可点击效果? On Lollipop it's a ripple effect.
在棒棒糖上,这是一种涟漪效应。 On previous ones it's full color changing within the boundaries of the CardView.
在以前的版本中,它在 CardView 的边界内全色变化。 I'd also like to customize the color of the clickable effect, and let it also be checkable.
我还想自定义可点击效果的颜色,并让它也可以检查。
How do I make a dark-theme CardView ?如何制作深色主题 CardView ?
This was requested on google at https://code.google.com/p/android/issues/detail?id=194497这是在谷歌上要求的https://code.google.com/p/android/issues/detail?id=194497
But after release of Android Support Library, revision 23.2.1 (March 2016) This functionality is added.但在 Android 支持库发布后,修订版23.2.1 (2016 年 3 月)添加了此功能。
Add dark theme for CardView为 CardView 添加深色主题
update Support Library to Android Support Library to 23.2.1
将支持库更新为
Android Support Library to 23.2.1
Add below attribute to your cardview将以下属性添加到您的 cardview
style="@style/CardView.Dark"
<?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="wrap_content">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/cards"
style="@style/CardView.Dark"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:padding="10dp">
<TextView
android:id="@+id/usersName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingTop="10dp"
android:text="Username"
android:textColor="#FFFFFF" />
<TextView
android:id="@+id/others"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/usersName"
android:layout_centerVertical="true"
android:paddingTop="10dp"
android:text="Others"
android:textColor="#FFFFFF" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.