我想在按钮点击上添加一个涟漪动画.我确实喜欢下面但它需要minSdKVersion到21.
ripple.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item>
<shape android:shape="rectangle">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
按键
<com.devspark.robototextview.widget.RobotoButton
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple"
android:text="@string/login_button" />
Run Code Online (Sandbox Code Playgroud)
我想让它向后兼容设计库.
怎么做到这一点?
我创建了一个按钮,我想为该按钮添加涟漪效果!
我创建了一个按钮bg XML文件:(bg_btn.xml)
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#FFFFFF" android:endColor="#00FF00" android:angle="270" />
<corners android:radius="3dp" />
<stroke android:width="5px" android:color="#000000" />
</shape>
Run Code Online (Sandbox Code Playgroud)
这是我的涟漪效应文件:(ripple_bg.xml)
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="#f816a463"
tools:targetApi="lollipop">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#f816a463" />
</shape>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
这是我想要添加涟漪效果的按钮:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_centerHorizontal="true"
android:layout_marginTop="173dp"
android:textColor="#fff"
android:background="@drawable/ripple_bg"
android:clickable="true" />
Run Code Online (Sandbox Code Playgroud)
但添加涟漪效果后按钮背景是透明的,只有在点击时才会显示按钮,如下所示:
点击之前
点击

但我需要按钮背景颜色和涟漪效果,我在Stack Overflow的不同博客中发现了一些此代码,但它仍然无效!
我很想为我的开源库启用触摸反馈.
我创造了一个RecyclerView和一个CardView.该CardView包含不同的区域不同的onClick动作.现在,如果用户点击卡中的任何位置,我很乐意触发Ripple效果,但我无法实现此行为.
这是我的listitem,您也可以在GitHub上找到它:https://github.com/mikepenz/AboutLibraries/blob/master/library/src/main/res/layout/listitem_opensource.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@drawable/button_rect_normal"/>
<LinearLayout
android:padding="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/libraryName"
android:textColor="@color/title_openSource"
android:textSize="@dimen/textSizeLarge_openSource"
android:textStyle="normal"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"/>
<TextView
android:id="@+id/libraryCreator"
android:textColor="@color/text_openSource"
android:textStyle="normal"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="right"
android:maxLines="2"
android:textSize="@dimen/textSizeSmall_openSource"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:background="@color/dividerLight_openSource"/>
<TextView
android:id="@+id/libraryDescription"
android:textSize="@dimen/textSizeSmall_openSource"
android:textStyle="normal"
android:textColor="@color/text_openSource"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="20">
</TextView>
<View
android:id="@+id/libraryBottomDivider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:background="@color/dividerLight_openSource"/>
<LinearLayout
android:id="@+id/libraryBottomContainer"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:paddingRight="8dp" …Run Code Online (Sandbox Code Playgroud) android touch-feedback android-cardview rippledrawable android-recyclerview
我有一个RecyclerView扩展以下网格项:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/children_tile_border"
android:layout_marginTop="@dimen/children_tile_border"
android:clickable="true"
android:focusable="true"
android:background="?selectableItemBackground"
tools:ignore="RtlHardcoded">
<com.example.app.ui.widget.SquareImageView
android:id="@+id/child_picture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_alignParentBottom="true"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="68dp"
android:background="@color/tile_text_background"
android:gravity="center_vertical"
android:layout_alignParentBottom="true">
..............
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但除非我将SquareImageView's可见性设置为不可见,否则不会出现涟漪效应.似乎涟漪效应低于SquareImageView.我怎么能把它画成SquareImageView?
我正在尝试将Ripple效果添加到RecyclerView项目中.我在网上看了一下,但找不到我需要的东西.我已经尝试了android:background属性并将RecyclerView其设置为"?android:selectableItemBackground"但它没有工作:
我的父布局是这样的
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/dailyTaskList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:scrollbars="vertical" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
和适配器模板如下所示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/txtTitle"
style="@style/kaho_panel_sub_heading_textview_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txtDate"
style="@style/kaho_content_small_textview_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
请给我解决方案
android android-layout android-fragments recycler-adapter android-recyclerview
嗨,我想让我的线性布局像按钮一样工作.我的意思是当状态改变时我试图改变它的背景颜色.我使用了选择器来解决它,但它没有用.
我寻找解决方案,他们说的只是添加可点击属性.我已经做到了.
我的LinearLayout包含两个LinearLayout,每个包含9个TextView.它们完全填满了我的LinearLayout.
我想到的是它的孩子正在吸收点击事件,而我的LinearLayout并没有将其状态改为按下状态.
所以我在我的LinearLayout的每个子节点上都将clickable和focusalbe属性设置为false.
但是,它仍然是一样的.
这是我的代码.
这是选择器jbbtn.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_enabled="true" android:state_pressed="true"
android:drawable="@drawable/jbbtn_pressed"/>
<item android:state_enabled="true"
android:drawable="@drawable/jbstyle_transparent"/>
<item android:state_enabled="false" android:drawable="@drawable/jbbtn_disabled"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
这是我的LinearLayout
<LinearLayout
android:id="@+id/llCurrents"
android:background="@drawable/jbbtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/llTimer"
android:layout_below="@id/btnMenu"
android:layout_marginRight="3sp"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:padding="3sp" >
~~~~~~
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ImageButton,
android:background="?attr/selectableItemBackground"但我的应用程序崩溃了.我只是按照这个答案和这个问题.任何的想法?
谢谢你的帮助.
activity.xml
<ImageButton
android:id="@+id/signUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/signIn"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"
android:background="?attr/selectableItemBackground"
android:src="@drawable/sign_up"
android:contentDescription="@string/button_sign_up"
/>
Run Code Online (Sandbox Code Playgroud)
记录猫
05-31 18:50:24.077: W/dalvikvm(28619): threadid=1: thread exiting with uncaught exception (group=0x41d0b2a0)
05-31 18:50:24.082: E/AndroidRuntime(28619): FATAL EXCEPTION: main
05-31 18:50:24.082: E/AndroidRuntime(28619): java.lang.RuntimeException: Unable to start activity ComponentInfo{yai.properti.tujuh.tujuh.tujuh/yai.properti.tujuh.tujuh.tujuh.WelcomeActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageButton
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.access$700(ActivityThread.java:140)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
05-31 18:50:24.082: E/AndroidRuntime(28619): at …Run Code Online (Sandbox Code Playgroud) 在参考适用于Android L的RippleDrawable时,https://developer.android.com/reference/android/graphics/drawable/RippleDrawable.html,有一种方法可以屏蔽掉视图中的涟漪效果.掩蔽完成为
<ripple android:color="#ff0000ff">
<item android:drawable="@drawable/white" />
</ripple>
Run Code Online (Sandbox Code Playgroud)
我们也可以使用它来掩盖它
<ripple android:color="#ff0000ff">
<item android:drawable="@drawable/black" />
</ripple>
Run Code Online (Sandbox Code Playgroud)
如文档中所述,屏幕上没有绘制遮罩层,只是掩盖了涟漪效应.我很好奇,为什么要在那里设置一种颜色(白色或黑色或任何东西)?我们是否有任何重要的颜色作为面具,或者它确实会有任何价值吗?
希望有人开导......谢谢!
使用selectableItemBackground属性进行“触摸波纹效果”时,似乎正常触摸速度太快,无法出现“触摸波纹”。我必须触摸更长的时间,一切正常。是否有可能以某种方式强制这种效果,即使是短距离触摸?