Android中的Button自定义点击效果实例代码

2016-02-19 09:35 10 1 收藏

有一种朋友不在生活里,却在生命力;有一种陪伴不在身边,却在心间。图老师即在大家的生活中又在身边。这么贴心的服务你感受到了吗?话不多说下面就和大家分享Android中的Button自定义点击效果实例代码吧。

【 tulaoshi.com - 编程语言 】

方法一
1.放在drawable下的selector.xml文件
代码如下:

android="http://schemas.android.com/apk/res/Android"

   android:drawable="@drawable/temp2" /

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

2.布局文件main.xml
代码如下:

http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
   
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    /
 android:drawableTop="@drawable/shouru"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="@string/button"
 android:background="@drawable/selector"/

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

 方法二
1.布局文件main.xml
[code]
http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
   
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    /
 android:id="@+id/button"
 android:drawableTop="@drawable/shouru"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="@string/button"
 android:background="@drawable/temp4"/

2.主要的java代码,实现点击效果:
代码如下:

   Button button = (Button) this.findViewById(R.id.button);
   button.setOnTouchListener(new Button.OnTouchListener(){
   @Override
   public boolean onTouch(View v, MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_DOWN){  
                    v.setBackgroundResource(R.drawable.temp1);  
                    Log.i("TestAndroid Button", "MotionEvent.ACTION_DOWN");
                }  
                else if(event.getAction() == MotionEvent.ACTION_UP){  
                    v.setBackgroundResource(R.drawable.temp2);
                    Log.i("TestAndroid Button", "MotionEvent.ACTION_UP");
                }
    return false;
   }
  });

来源:http://www.tulaoshi.com/n/20160219/1591359.html

延伸阅读
以前也模仿者ireader实现了书架的效果,但是那种是使用listview实现的,并不好用。绝大多数都是用gridview实现的,网上这方面资料比较少,有些开源的电子书都是重点做了阅读,并没有像ireader和QQ阅读这样的书架效果。 书架这种效果我早就实现了,本来想做一个完美的电子书,但是因为自己的懒惰,仅仅持续了一两天,今天又找到了以前的代码分...
标签: 电脑入门
Excel函数虽然丰富,但并不能满足我们的所有需要。我们可以自定义一个函数,来完成一些特定的运算。下面,我们就来自定义一个计算梯形面积的函数: 1、执行工具→宏→Visual Basic编辑器菜单命令(或按Alt+F11快捷键),打开Visual Basic编辑窗口。 2、在窗口中,执行插入→模块菜单命令,插入一个新的模块模块1。 3、在右边的代...
描述代码/////////checkboxcolumn.cs////////////////using System;using System.Web;using System.Web.UI.WebControls; namespace MSDN{ /// /// CheckBoxColumn 的摘要说明。 /// public class CheckBoxColumn : DataGridColumn { private string m_allText; public CheckBoxColumn() { CheckBoxAllText="全选"; } public string C...
在VC中提供了两种很方便的编辑控件(CEdit 和CRichEditCtrl),一般来说这两种控件已经满足了我们大部分的需要,不过只有CEdit控件能响应我们鼠标右键消息,通过右键我们很容易的操作我们的编辑,而在CRichEditCtrl控件中我们不能得到这样的操作,同时CRichEditCtrl是能够包含各种格式的内容,就好像Word一样能够写入各种不同的字体,不过C...
标签: autocad教程
   在AutoCAD制图中,HATCH(图案填充)命令的使用较为频繁。CAD自带的图案库虽然内容丰富,但有时仍然不能满足我们的需要,这时我们可以自定义图案来进行填充。 AutoCAD的填充图案都保存在一个名为acad.pat的库文件中,其缺省路径为安装目录的\Acad2000\Support目录下。我们可以用文本编辑器对该文件直接进行编辑,添加自定义...

经验教程

892

收藏

8
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部