原文:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380143fd3d1027fa3c215cc790e161b31f4bc537c5719839b21321cee0f0facab676f330522b79cce8849ddb991282a8924347717804012d81eb2df037881769f09b5f959bae1a62592dec5a3dd4323cc44747d97838c4d0164dd19f60341e3b1e93e022e15&p=9b67833785cc43ff57ee9578614794&newp=882a9644d0951bfc57ef85624a5c81231610db2151d0d61f298e&user=baidu&fm=sc&query=android%B0%B4%C5%A5%D4%B2%BD%C7&qid=&p1=2


Android圆角的Button

Android圆角的Button  

2012-08-31 14:59:43|  分类:android |举报|字号 订阅


在res目录下的drawable-mdpi建立xml文件shape.xml,如下图所示:
Android 圆角的Button_第1张图片 

shape.xml
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.     xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:shape="rectangle">
  4.    
  5.     android:color="#FFFFFF" />
  6.    
  7.    
  8.     android:radius="5dip" />
  9.     

  10.    android:left="10dp"
  11.    android:top="10dp"
  12.    android:right="10dp"
  13.    android:bottom="10dp"
  14. />
复制代码main.xml
android:background="@drawable/shape"就使用了shape.xml资源

  1. <?xml version="1.0" encoding="utf-8"?>
  2. android="http://schemas.android.com/apk/res/android"
  3.     android:orientation="vertical"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent"
  6.     >
  7.     android:layout_width="fill_parent" 
  8.     android:layout_height="wrap_content" 
  9.     android:text="@string/hello"
  10.     /> 
  11.         android:id="@+id/roundButton"
  12.         android:text="圆角按钮 "
  13.         android:layout_width="wrap_content" 
  14.     android:layout_height="wrap_content" 
  15.     android:background="@drawable/shape"
  16.         />


复制代码
strings.xml
  1. <?xml version="1.0" encoding="utf-8"?>

  2.     Hello World, RoundButtonDemoActivity!
  3.     RoundButtonDemo


复制代码
RoundButtonDemoActivity.java
  1. package com.android.RoundButtonDemo.activity;

  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.view.View.OnClickListener;
  6. import android.widget.Button;
  7. import android.widget.Toast;

  8. public class RoundButtonDemoActivity extends Activity {
  9.     Button roundButton;
  10.     @Override
  11.     public void onCreate(Bundle savedInstanceState) {
  12.         super.onCreate(savedInstanceState);
  13.         setContentView(R.layout.main);
  14.         
  15.         roundButton=(Button)findViewById(R.id.roundButton);
  16.       //使用匿名类注册Button事件
  17.         roundButton.setOnClickListener(new OnClickListener()
  18.       {                
  19.                         public void onClick(View v)
  20.                         {
  21.                                 Toast.makeText(RoundButtonDemoActivity.this, "你点击了圆角按钮",Toast.LENGTH_LONG).show();
  22.                         }
  23.                 });
  24.     }
  25. }
复制代码
效果图:
Android 圆角的Button_第2张图片 

PS:我正在参加IT博客大赛,欢迎大家来投我一票的
http://blog.51cto.com/contest2011/3061169

源代码下载:

 RoundButtonDemo.rar (41.38 KB, 下载次数: 22) 

摘自: http://www.apkbus.com/forum.php?mod=viewthread&tid=17622


更多相关文章

  1. 第一行代码:AlertDialog
  2. android按钮按下的效果
  3. Android 自动更新代码
  4. Android 自制一个工作日历 原代码
  5. android 图片背景使用这种方式很爽
  6. android获得圆角图片
  7. Android在Button按钮上同时显示文字和图片
  8. android ViewFlipper实现图片轮播

随机推荐

  1. Android加载SVG实现交互式地图绘制
  2. Windows下通过虚拟机搭建android的linux
  3. Android之实现点击波纹效果
  4. Android adb shell命令大全
  5. android数据库操作出现的 android.databa
  6. Android的EditText控件常用属性
  7. Android架构实例分析之注册hello HAL的JN
  8. android 四种启动模式
  9. 剖析andriod联系人
  10. android:launchMode="singleTask" intent