当前位置: 移动技术网 > 移动技术>移动开发>Android > Android编程实现简单设置按钮颜色的方法

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

2019年07月24日  | 移动技术网移动技术  | 我要评论

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

1.工程目录

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

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布局layout技巧总结》、《android视图view技巧总结》、《android开发入门与进阶教程》、《android调试技巧与常见问题解决方法汇总》、《android多媒体操作技巧汇总(音频,视频,录音等)》、《android基本组件用法总结》及《android控件用法总结

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网