zoukankan      html  css  js  c++  java
  • android 按钮背景 圆角+点击效果

    今天做了个按钮,不想麻烦美工做图片,又不喜欢方角的图片,就用xml做了圆角的图片,做好之后发现,点击的时候看不出点击效果了,xml可以定义点击效果,

    就想怎么能两个一起实现,网上找了下大致看了一遍都不是我想要的,就慢慢的试了试,结果两者一结合就OK了。

     1  <Button 
     2          android:id="@+id/repeat"
     3          android:layout_width="fill_parent"
     4          android:layout_height="wrap_content"
     5          android:text="重新开始答题"
     6          android:layout_marginLeft="10dip"
     7          android:layout_marginRight="10dip"
     8          android:layout_marginTop="25dip"
     9          android:background="@drawable/button_style"
    10          />
    button_style如下:

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
     3     <item android:state_pressed="true">
     4           <shape xmlns:android="http://schemas.android.com/apk/res/android"
     5             android:shape="rectangle">
     6             <!-- 圆角深红色按钮 -->
     7             <solid android:color="#4D0A0A"/>
     8             <corners android:radius="8dip"/>
     9          </shape>  
    10     </item>
    11        
    12     <item android:state_pressed="false">
    13         <shape xmlns:android="http://schemas.android.com/apk/res/android"
    14             android:shape="rectangle">
    15             <!-- 圆角红色按钮 -->
    16             <solid android:color="#D9534F"/>
    17             <corners android:radius="8dip"/>
    18          </shape> 
    19     </item>
    20 
    21 </selector>
    button_style.xml是定义在drawable下的xml文件.
    <corners android:radius="8dip"/> 定义圆角大小。
     
  • 相关阅读:
    怎么往mac中finder个人收藏里添加文件夹
    UIView 动画
    添加.pch文件
    声明属性的关键字
    创建app前的环境配置/AppIcon/启动图片
    修改动画的旋转支点
    实现自定义xib和storyboard的加载,
    Quartz2D绘图 及实例:下载进度
    帧动画
    在职研究生第一单元第二单元第三单元第四单元是什么?
  • 原文地址:https://www.cnblogs.com/mauiie/p/3716209.html
Copyright © 2011-2022 走看看