【问题标题】:Is ripple effect/radical reaction possible on switchcompat?switchcompat 是否可能产生涟漪效应/激进反应?
【发布时间】:2017-01-07 02:13:57
【问题描述】:

我试图在 switch 兼容上应用激进反应/涟漪效应,但我能从中得到的最多只是一个短暂的效果。我在一行中有一个开关,一旦打开和关闭开关,我想在整个行中突出显示。目前唯一突出的是开关,它也没有涟漪效应,就像开关本身的暗淡亮点一样。一旦开关被翻转,是否可以在整个行中发出波浪/涟漪效应? 这是我的代码:

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/altercolor2"
         android:padding="@dimen/common_padding">

        <com.myapp.utils.FontTextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            android:paddingTop="@dimen/common_top_padding"
            android:paddingLeft="0dp"
            android:paddingBottom="@dimen/common_bottom_padding"
            android:textSize="@dimen/title"
            foo:customFont="proxima-nova-regular.ttf"
            android:text="@string/display_image" />

        <android.support.v7.widget.SwitchCompat
            android:id="@+id/display_image_toggle_control"
            foo:theme="@style/MyMaterialTheme.Switch"
            android:background="?attr/selectableItemBackgroundBorderless"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center_vertical"
            android:layout_marginLeft="@dimen/toggle_margin_leftright"
            android:layout_marginRight="2dp" />
    </FrameLayout>

【问题讨论】:

    标签: android android-layout android-fragments material-design switchcompat


    【解决方案1】:

    您可以添加自己的波纹效果,创建一个drawable-v21 文件夹并将以下可绘制对象作为FrameLayout 的背景我想解决您的问题:

    <?xml version="1.0" encoding="utf-8"?>
    
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
        android:color="@color/gray_light">
        <item
            android:id="@android:id/mask"
            android:drawable="@color/gray" />
    </ripple>
    

    同时添加:

    android:clickable="true"
    android:focusable="true"
    

    是否可以在整个过程中发出波浪/涟漪效果 拨动开关后排?

    我认为您需要在视图中设置foregroundbackground

    【讨论】:

    • 上述框架布局包含在 schemas.android.com/apk/res/android" xmlns:foo="schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android :background="@color/altercolor2" > ,我在前景和背景中添加什么,我在哪里添加可聚焦的开关或包含它的框架布局?
    • 将焦点和可点击添加到您的根目录。
    • 我如何增加涟漪效应的直径,目前它似乎中途死亡?
    • 您可以将大小添加到您的波纹可绘制对象 [use android:constantSize="true"] 并设置您的大小; developer.android.com/guide/topics/resources/…
    • 那仍然没有帮助半径增加,它只是现有代码的一半大小,你有任何关于开关的代码示例吗?
    猜你喜欢
    • 1970-01-01
    • 2016-04-25
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    相关资源
    最近更新 更多