当前位置: 首页 > 知识库问答 >
问题:

如何在桌面物品的图像按钮上设置波纹效果

雍骏俊
2023-03-14
<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:gravity="center_horizontal"
    android:layout_gravity="center_horizontal"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    >

    <ImageButton
        android:id="@+id/ess_btn_leave"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:src="@drawable/leave"
        android:background="?android:attr/selectableItemBackground"
        />

    <ImageButton
        android:id="@+id/ess_imgbtn_expence"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:background="@null"
        android:src="@drawable/expence"
        />
</TableRow>

共有1个答案

姬向明
2023-03-14

您可以在图像视图上使用Android:foreground=“?attr/selectableitembackground”。对于默认纹波

对于自定义ripple,您需要在drawable-v21中创建两个文件-background_ripple.xml

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_shortAnimTime"
android:color="@color/lightGrey" >

<item>
    <shape android:shape="rectangle" >
        <solid android:color="@color/white" />
    </shape>
</item>

在您的普通绘图版本以上21

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <color android:color="@color/lightGrey" />
    </item>
    <item>
        <color android:color="@color/white" />
    </item>
</selector>
 类似资料:
  • 问题内容: 我想将背景设置为。使用XML时没有问题(有效) …但是我必须在Java代码中执行此操作,因此我已经尝试过 …而且它不起作用,实际上我在第二行得到了一个。因此,在尝试了这种变体之后,我认为资源是一种颜色。 这个没有启动异常,但是…不起作用(按下时背景没有变化,但是按下时状态必须改变)…有什么建议吗? 问题答案: 您可以使用这种方式。

  • 我正在试着做记忆游戏。我有12个按钮和6个图像。 我想随机设置图像到按钮。一个图像到2个按钮。 我知道这个但是不知道如何在这里使用它。 编辑: 你用过这个吗 如何设置此图标的可见(假)之类的内容?

  • 我在android中使用FAB,我增加了Src图像大小来覆盖FAB,但现在每当我点击FAB时,涟漪效应会显示在图像后面,而不是上面,这不会给人一种FAB被点击的感觉 我的晶圆厂代码

  • 问题内容: 我期望以下两个脚本具有相同的输出。 但是执行 脚本1 时,按钮上没有显示图像。但是, 脚本2 效果很好。 脚本1 剧本2 问题答案: 对图像对象的唯一引用是局部变量。当退出时,被当作垃圾回收的局部变量,因此图像被破坏。在第二个示例中,由于映像是在全局级别创建的,因此它永远不会超出范围,因此也不会进行垃圾回收。 要解决此问题,请保存对图像的引用。例如,代替use 。

  • 波纹效果是一个外部库,主要用于实现 Material Design 中的点击效果。 应用波纹效果 给按钮添加波纹效果,你只要将 waves-effect 类放到按钮中。如果你想这个波纹效果更白,增加 waves-effect waves-light 作为按钮的类。 <a class="waves-effect waves-light btn-large" href="#">Wave</a> 自定

  • 嗨,所以我有点困惑,想知道是否有人能给我指明正确的方向。 去使用Lollipop和Lollipop前的谷歌Play商店 您将在lollipop上看到,可选择视图具有涟漪效应。 Android:background=“?attr/selectableitembackground” 来获得Lollipop前的高亮效果,但这覆盖了我的背景。我怎么能把这个设置在我当前的背景之上呢? 另外,我必须为我的应用