Pri*_*raj 7 android background ripple android-drawable
我的Xml代码:
<Button
android:id="@+id/link_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/google_btn" />
Run Code Online (Sandbox Code Playgroud)
我正在应用默认涟漪效应
<Button
android:id="@+id/link_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground" />
Run Code Online (Sandbox Code Playgroud)
但我需要按钮的背景"@drawable/google_btn"用
"?android:attr/selectableItemBackground".这意味着我需要自定义背景的涟漪效果.
在您的drawable-v21文件夹中,您可以自己编写涟漪效果代码.制作一个可绘制的xml文件并设置起始标记ripple.像这样 :
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/colorAccentDark">
<item>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@color/button_accent_dark"
android:state_checked="false"/>
<item
android:drawable="@color/button_accent"
android:state_checked="true" />
<item
android:drawable="@color/button_accent_dark" />
</selector>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
当按钮具有drawable的背景时,我们可以为前景参数添加涟漪效果.检查下面的代码,它的工作是我的按钮,具有不同的背景
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center"
android:layout_centerHorizontal="true"
android:background="@drawable/shape_login_button"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:text="@string/action_button_login"
/>
Run Code Online (Sandbox Code Playgroud)
为涟漪效果添加以下参数
android:foreground="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight" >
<item
android:id="@android:id/mask"
android:drawable="@drawable/btn_rectangle"/>
<item android:drawable="@drawable/btn_rect_states"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)
在drawables中尝试上面的代码,根据需要提供自己的自定义可绘制背景.
| 归档时间: |
|
| 查看次数: |
8192 次 |
| 最近记录: |