android中button圆角,Android开发学习笔记:圆角的Button

在res目录下的drawable-mdpi建立xml文件shape.xml,如下图所示:

17101858-701c8eea74a5403b823a88700e7a88b7.jpg

shape.xml

copycode.gif<?xml  version="1.0" encoding="UTF-8"?> 

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

android:shape="rectangle">

 

android:left="10dp"

android:top="10dp"

android:right="10dp"

android:bottom="10dp" /> 

copycode.gif

main.xml

在android:background="@drawable/shape"就使用了shape.xml资源

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

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>   

android:id="@+id/roundButton"

android:text=" 圆角按钮 "

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/shape"

/> 

copycode.gif

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

Hello World, RoundButtonDemoActivity!

RoundButtonDemo 

RoundButtonDemoActivity.java

copycode.gifpackage com.android.RoundButtonDemo.activity;  

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.Toast;

public class RoundButtonDemoActivity extends Activity {

Button roundButton;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

roundButton=(Button)findViewById(R.id.roundButton);

//使用匿名类注册Button事件

roundButton.setOnClickListener(new OnClickListener()

{

public void onClick(View v)

{

Toast.makeText(RoundButtonDemoActivity.this, "你点击了圆角按钮",Toast.LENGTH_LONG).show();

}

});

}

}

copycode.gif

效果图:

17102112-0ee2b7d5e5154f36bd99b0fe01635fe1.jpg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值