最近该死叫我改一个Button的效果,就是按住要一个效果,放开要一个。好吧,抄袭网上的。

在res/drawable/button_style.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_pressed="true" android:drawable="@drawable/play_press" /><item android:state_focused="true" android:drawable="@drawable/play_press" /><item android:drawable="@drawable/play" /></selector>

当然了要放两种图片,play_press.png和play.png

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" /><Button android:id="@+id/button1"android:layout_width="wrap_content" android:layout_height="wrap_content"android:background="@drawable/button_style"></Button></LinearLayout>

这个是java文件

package com.pocketdigi.button;import android.app.Activity;import android.os.Bundle;public class ButtonActivity extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);    }}

效果就是点击 和 放开button是不同的效果

更多相关文章

  1. 使用Visual Studio 2015开发Android(安卓)程序
  2. Android中Dialog的使用
  3. Android: R cannot be resolved to a variable
  4. Android(安卓)Studio 连接夜神模拟器
  5. TextView的跑马灯效果,还有焦点问题
  6. Android(安卓)PDF开发:android-pdfview
  7. Android设置透明、半透明等效果
  8. Android(安卓)编译系统分析
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android字体多样式和动画TextDrawable
  2. [Android]美国VOA英语学习软件,无广告
  3. Android(安卓)JNI开发入门之二
  4. Android之android studio如何获取证书指
  5. 7、从头学Android之TextView控件
  6. 解析华清远见自主研发Cortex-A9开源Andro
  7. Android之数据统计TalkingData集成
  8. Android中的AppWidget
  9. Android(安卓)技能树
  10. Android尺寸单位