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"/> 定义圆角大小。
     
  • 相关阅读:
    POJ 3253 Fence Repair STL 优先队列
    P1196 [NOI2002]银河英雄传说 题解
    UVA1316 Supermarket 题解
    P1955 [NOI2015]程序自动分析 题解
    P3807 【模板】卢卡斯定理 题解
    P2480 [SDOI2010]古代猪文 题解
    题解 P4778 【Counting swaps】
    P1313 计算系数 题解
    P3810 【模板】三维偏序(陌上花开)题解
    P1072 Hankson 的趣味题 题解
  • 原文地址:https://www.cnblogs.com/mauiie/p/3716209.html
Copyright © 2011-2022 走看看