相关疑难解决方法(0)

如何以编程方式在LinearLayout上设置Ripple效果?

我想将背景设置android.R.attr.selectableItemBackground为a LinearLayout.使用XML时没有问题(可行)

<LinearLayout
    android:id="@+id/llMiner"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?android:attr/selectableItemBackground"
    android:clickable="true" >
Run Code Online (Sandbox Code Playgroud)

...但我必须在java代码中这样做,所以我试过这个

llMiner.setClickable(true);
llMiner.setBackgroundResource(android.R.attr.selectableItemBackground);
Run Code Online (Sandbox Code Playgroud)

......它不起作用,事实上我得到了NotFoundException第二行.所以在我尝试了这个变体后认为资源是一个颜色.

llMiner.setClickable(true);
llMiner.setBackgroundColor(android.R.attr.selectableItemBackground);
Run Code Online (Sandbox Code Playgroud)

这个没有启动异常,但是......不起作用(按下时没有改变背景,但是状态改变按下它必须这样做)...任何建议?

android background clickable android-linearlayout

37
推荐指数
1
解决办法
2万
查看次数

Android imagebutton ripple effect

Okay, so I understood ripple effect is only available LOLLIPOP and up. But, still, when setting up my ImageButton, I fail to get a nice ripple effect that would work like a "regular" Button, just show an image instead (and transparent bg)...

I added AppCompat v7 and put the second layout in my drawable/layout-v21 folder, which has the following button in it:

<ImageButton
    android:id="@+id/forward"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:width="15dp"
    android:scaleType="fitCenter"
    android:height="15dp"
    android:padding="25dp"
    style="@style/Widget.AppCompat.ImageButton"
    android:src="@drawable/forwardplay" />
Run Code Online (Sandbox Code Playgroud)

But the background is grey and the …

android rippledrawable android-5.0-lollipop

3
推荐指数
2
解决办法
6318
查看次数