Android開發(fā)學(xué)習(xí)筆記:圓角的Button

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

為沿河等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及沿河網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站制作、成都網(wǎng)站設(shè)計、沿河網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!

Android開發(fā)學(xué)習(xí)筆記:圓角的Button

shape.xml

Android開發(fā)學(xué)習(xí)筆記:圓角的Button

<?xml version="1.0" encoding="UTF-8"?> <shape 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <!-- 填充的顏色 --> 
    <solid android:color="#FFFFFF" /> 
    <!-- 設(shè)置按鈕的四個角為弧形 --> 
    <!-- android:radius 弧形的半徑 --> 
    <corners android:radius="5dip" /> 
      <!-- padding:Button里面的文字與Button邊界的間隔 --> <padding 
   android:left="10dp" 
   android:top="10dp" 
   android:right="10dp" 
   android:bottom="10dp" /> </shape>

Android開發(fā)學(xué)習(xí)筆記:圓角的Button

 

main.xml

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

Android開發(fā)學(xué)習(xí)筆記:圓角的Button

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > <TextView    
    android:layout_width="fill_parent"   
    android:layout_height="wrap_content"   
    android:text="@string/hello" 
    />   <Button   
    android:id="@+id/roundButton" 
    android:text=" 圓角按鈕 " 
    android:layout_width="wrap_content"   
    android:layout_height="wrap_content"   
    android:background="@drawable/shape" 
    /> </LinearLayout>

Android開發(fā)學(xué)習(xí)筆記:圓角的Button

strings.xml

<?xml version="1.0" encoding="utf-8"?> <resources> 
    <string name="hello">Hello World, RoundButtonDemoActivity!</string> 
    <string name="app_name">RoundButtonDemo</string> </resources>

RoundButtonDemoActivity.java

Android開發(fā)學(xué)習(xí)筆記:圓角的Button

package 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();  
            }  
        });  
    }  
}

Android開發(fā)學(xué)習(xí)筆記:圓角的Button

效果圖:

Android開發(fā)學(xué)習(xí)筆記:圓角的Button

分享名稱:Android開發(fā)學(xué)習(xí)筆記:圓角的Button
文章位置:http://bm7419.com/article8/igccop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗網(wǎng)站制作、域名注冊、網(wǎng)站收錄、云服務(wù)器、面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)