1. 首先在drawable文件夹定义一个shape.xml文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#e6e6" />

<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp" />

<padding
android:left="30dp"
android:top="0dp"
android:right="30dp"
android:bottom="0dp"
/>
</shape>


2. 在main.xml文件中,button使用这个shape.xml,如下:

<Button
android:id="@+id/button_next"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:text="@string/button_next"
android:textSize="@dimen/label_text_size"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:gravity="center_horizontal|center_vertical"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/shape"
/>

这时,该button就显示如shape.xml定义的形状。


3. 在代码中动态修改button 背景颜色,代码如下:

GradientDrawable bgShape = (GradientDrawable)buttonNext.getBackground();
bgShape.setColor(Color.BLUE);


更多相关文章

  1. Android(安卓)Studio - 详解build.gradle
  2. Android手写数据库框架设计(删改查)
  3. Android(安卓)MVVM Demo
  4. AndroidStudio中的图片资源存放位置以及drawable文件夹的创建方
  5. android本地化语言与theme的实现(一)
  6. Android(安卓)应用导入第三方jar包
  7. Android(安卓)strings.xml文件定义字符串中的标签
  8. 实现Android的消息通知栏
  9. 【转】Eclipse 开发Android小程序遇到的问题总结

随机推荐

  1. android消息机制原理详解
  2. 【安卓学习之开发工具】 Android Studio
  3. 使用系统libsqlite.so 进行ndk 开发
  4. Android API Level概念
  5. Android Studio 工程视图&项目构成
  6. android 字体的使用
  7. Android中TextVIew一些属性
  8. [置顶] Android(安卓)开发中Parcel存储类
  9. Android安全加密:消息摘要Message Digest
  10. Android的布局方法