【问题标题】:Lollipop RippleDrawable to TextViewLollipop RippleDrawable 到 TextView
【发布时间】:2016-03-25 02:13:34
【问题描述】:

drawable-v21/ripple.xml:

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

文本视图:

<TextView
     android:id="@+id/tv_back"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="?attr/selectableItemBackground"
     android:clickable="true"
     android:gravity="center"
     android:minWidth="200dp"
     android:text="@string/back_to_school"
     android:textColor="@color/color_sign_status"
     android:textSize="16sp"/>

如果我想将RippleDrawable设置为TextView,我必须设置android:background="?attr/selectableItemBackground",但是如何设置我的自定义背景呢?

或者只是顺便设置背景:

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="20dp"
    android:background="@drawable/bg_sign_tip"
    android:gravity="center">

    <TextView
         android:id="@+id/tv_back"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="?attr/selectableItemBackground"
         android:clickable="true"
         android:gravity="center"
         android:minWidth="200dp"
         android:text="@string/back_to_school"
         android:textColor="@color/color_sign_status"
         android:textSize="16sp"/>

</LinearLayout>

如果我使用Button,结果如下:

这太可怕了。有没有其他办法?

【问题讨论】:

  • android:background="@drawable/ripple" ?
  • 我知道问题出在哪里。TextView 只需将“android:clickable”设置为true,Ripple 始终可以工作,然后您可以自己设置背景。

标签: android android-5.0-lollipop textview rippledrawable


【解决方案1】:

我认为这可以帮助您: 您必须将按钮的背景设置为可以在 XML 中定义的 RippleDrawable。 (我将其命名为 holo_blue_ripple.xml)

<item android:drawable="@android:color/holo_blue_bright"/> <!-- normal color -->

然后用 android:background="@drawable/holo_blue_ripple" 引用它

【讨论】:

    猜你喜欢
    • 2014-08-27
    • 1970-01-01
    • 2015-10-07
    • 2015-03-03
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多