为文字/图片添加按压效果

1、文字

layout布局:

<TextView

     android:layout_width="@dimen/textview_button_width" 
     android:layout_height="match_parent" 
     android:text="@string/wifi_item_hulv"
     android:textColor="@drawable/selector_upgrade_text_press"
     android:textSize="@dimen/text_size_selected" />

selector_upgrade_text_press xml文件

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
   <item 
      android:color="@color/text_pressed_blue" android:state_pressed="true" />

   <item 
      android:color="@color/switch_general_track_check_color"/> 
</selector>

2、svg图片

layout布局:

<ImageView android:id="@+id/iv_bt_loading_down" 
android:layout_width="@dimen/wifi_signal_height" 
android:layout_height="@dimen/wifi_signal_height" 
android:background="@drawable/ic_icon_general_update_72" />

svg图片:

<vector xmlns:android="http://schemas.android.com/apk/res/android" 
   android:width="72dp" 
   android:height="72dp" 
   android:viewportWidth="72" 
   android:viewportHeight="72"> 
 <path 
    android:pathData="M0.5,0.5h71v71h-71z" 
    android:strokeAlpha="0" 
    android:strokeWidth="1" 
    android:fillColor="#D8D8D8" 
    android:strokeColor="#979797" 
    android:fillType="evenOdd" 
    android:fillAlpha="0"/> 
 <path android:pathData="M21,34.5C21.8284,34.5 22.5,35.1716 22.5,36C22.5,
     43.4558 28.5442,49.5 36,49.5C39.6279,49.5 43.0248,48.0644 45.5407" 
    android:strokeWidth="1" 
    android:fillColor="@color/selector_upgrade_ic_press" 
    android:fillType="nonZero" 
    android:strokeColor="#00000000"/> 
</vector>

在res目录下新建一个color目录,然后在这个color目录下新建一个selector_upgrade_ic_press xml文件

<?xml version="1.0" encoding="utf-8"?>

<selector   

  xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:color="@color/ic_state_pressed" android:state_pressed="true" />

  <item android:color="@color/ic_state_not_pressed"/>

</selector>

3、文字按钮

layout布局:

<TextView

  android:id="@+id/btn_pincode_cancel"

  style="@style/ConfirmButtonNew" 

  android:paddingStart="@dimen/confirm_btn_padding_start"

  android:paddingTop="@dimen/confirm_btn_padding_top"

  android:background="@drawable/round_blue_bg"

  app:layout_constraintStart_toStartOf="parent"

  app:layout_constraintBottom_toBottomOf="parent"

  android:text="@string/cancel"/>

 

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

  <item android:state_pressed="false">

    <shape>

      <corners android:radius="@dimen/round_bg_radius" />

      <solid android:color="@color/round_blue_bg_color"/>

    </shape>

  </item>

 <item android:state_pressed="true">

   <shape>

     <corners android:radius="@dimen/round_bg_radius" />

     <solid android:color="@color/round_blue_bg_color_press"/>

   </shape>

  </item>

</selector>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值