首页 > 系统 > Android > 正文

Android编程实现简单设置按钮颜色的方法

2019-10-23 19:44:05
字体:
来源:转载
供稿:网友

本文实例讲述了Android编程实现简单设置按钮颜色的方法。分享给大家供大家参考,具体如下:

1.工程目录

a.在res目录-新建drawble文件夹放入自定义图片

Android,设置,按钮颜色

2.main.xml

<?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"  />  <ImageButton  android:id="@+id/button"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:background="#000000"  android:src="@drawable/sy"  /></LinearLayout>

3.类代码

package com.YANSE;import android.app.Activity;import android.os.Bundle;import android.widget.ImageButton;public class YANSE extends Activity {  private ImageButton Image =null;  @Override  public void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.main);    Image=(ImageButton)findViewById(R.id.button);  }}

希望本文所述对大家Android程序设计有所帮助。


注:相关教程知识阅读请移步到Android开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表