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"/> 定義圓角大小。
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM