zoukankan      html  css  js  c++  java
  • Android开发学习笔记:圆角的Button

     

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

     shape.xml

    1. <?xml version="1.0" encoding="UTF-8"?> 
    2. <shape 
    3.     xmlns:android="http://schemas.android.com/apk/res/android" 
    4.     android:shape="rectangle"
    5.     <!-- 填充的颜色 --> 
    6.     <solid android:color="#FFFFFF" /> 
    7.     <!-- 设置按钮的四个角为弧形 --> 
    8.     <!-- android:radius 弧形的半径 --> 
    9.     <corners android:radius="5dip" /> 
    10.       
    11. <!-- padding:Button里面的文字与Button边界的间隔 --> 
    12. <padding 
    13.    android:left="10dp" 
    14.    android:top="10dp" 
    15.    android:right="10dp" 
    16.    android:bottom="10dp" 
    17. /> 
    18. </shape

    main.xml

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

    1. <?xml version="1.0" encoding="utf-8"?> 
    2. <LinearLayout xmlns: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. <TextView    
    8.     android:layout_width="fill_parent"   
    9.     android:layout_height="wrap_content"   
    10.     android:text="@string/hello" 
    11.     />   
    12. <Button   
    13.     android:id="@+id/roundButton" 
    14.     android:text=" 圆角按钮 " 
    15.     android:layout_width="wrap_content"   
    16.     android:layout_height="wrap_content"   
    17.     android:background="@drawable/shape" 
    18.     /> 
    19. </LinearLayout

     strings.xml

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

     RoundButtonDemoActivity.java

    1. package com.android.RoundButtonDemo.activity;  
    2.  
    3. import android.app.Activity;  
    4. import android.os.Bundle;  
    5. import android.view.View;  
    6. import android.view.View.OnClickListener;  
    7. import android.widget.Button;  
    8. import android.widget.Toast;  
    9.  
    10. public class RoundButtonDemoActivity extends Activity {  
    11.     Button roundButton;  
    12.     @Override 
    13.     public void onCreate(Bundle savedInstanceState) {  
    14.         super.onCreate(savedInstanceState);  
    15.         setContentView(R.layout.main);  
    16.           
    17.         roundButton=(Button)findViewById(R.id.roundButton);  
    18.       //使用匿名类注册Button事件  
    19.         roundButton.setOnClickListener(new OnClickListener()  
    20.       {       
    21.             public void onClick(View v)  
    22.             {  
    23.                 Toast.makeText(RoundButtonDemoActivity.this, "你点击了圆角按钮",Toast.LENGTH_LONG).show();  
    24.             }  
    25.         });  
    26.     }  

    效果图:

     

    本文出自 “IT的点点滴滴” 博客,请务必保留此出处http://liangruijun.blog.51cto.com/3061169/630051

  • 相关阅读:
    javascript--运算符
    线程池 的创建小列子,以及参数的介绍
    @SpringBootApplication注解
    SpringBoot 基础知识学习(二)——配置文件多环境配置
    springboot 配置文件读取的两种方式,以及使用到的注解解释
    用虚拟机安装了一台Linux系统,突然想克隆一台服务器,克隆后发现无法上网,如何解决?
    ---oracle 数据库的设计,PL/SQL(loop,for,if,case,while)
    xml的解析技术, 它们之间的区别?
    -----oracle优化之表分区
    --------oracle 的伪表和伪劣,简单的分页
  • 原文地址:https://www.cnblogs.com/sunshinelaila/p/4412272.html
Copyright © 2011-2022 走看看