«

android Lollipop(5.0)--touch feedback(触摸反馈)

时间:2024-3-2 17:33     作者:韩俊     分类: Android



1,可以使用view的backgroud


//有边界
?android:attr/selectableItemBackground
//没有边界----API 21才有
?android:attr/selectableItemBackgroundBorderless

可以在theme里更改默认的波纹颜色

 <style name="AppBaseTheme" parent="android:Theme.Material.Light">
        <!-- API 21 theme customizations can go here. -->
        <item name="android:colorControlHighlight">#0000FF</item>
    </style>


2,可以使用ripple(drawable/ripple.xml)

<!-- A red ripple masked against an opaque rectangle. -->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#ff0000ff" >

    <!-- 添加边界 -->
    <item 
        android:id="@android:id/mask"
        android:drawable="@color/defaults"/>

</ripple>

layout文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.demomaterialtouchfeedback.MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn_test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?android:attr/selectableItemBackground"
            android:text="@string/bound_ripple" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?android:attr/selectableItemBackgroundBorderless"
            android:text="@string/unbound_ripple" />
    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="@drawable/ripple"
        android:clickable="true"
        android:elevation="1dp"
        android:text="@string/hello_world" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:background="@drawable/ripple"
        android:clickable="true"
        android:elevation="1dp"
        android:text="@string/hello_world" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/ripple"
        android:clickable="true"
        android:elevation="1dp"
        android:orientation="vertical"
        android:visibility="gone" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:elevation="1dp"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <ListView
        android:id="@+id/listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>

</LinearLayout>



标签: android

热门推荐