- 浏览: 478763 次
- 性别:
- 来自: 北京
最新评论
-
fatalfeel:
Irrlicht 3d Engine is full open ...
转:Android世界的15款开源的游戏开发引擎 -
diyangxia:
BigDecimal怎么初始化全局变量呢
android如何保留小数点后x位数字 -
c1230v:
这是一个程序员应该用的方法吗?求靠谱一点
转:android WebView 控件加载本地sdcard中html文件图片的问题 -
dingbuoyi:
楼主是天才 真牛逼
转:Progressbar-设置自己的样式 -
panxiaoming2008:
记住:显示本地文件时 必须使用APK'>file:/// ...
Android使用WebView加载本地资源
使用 Button 时为了让用户有“按下”的效果,有两种实现方式: 1.JAVA代码实现: imageButton.setOnTouchListener(new OnTouchListener(){ 2.XML实现: <?xml version="1.0" encoding="UTF-8"?> 这个文件放在 drawable 目录下面。命名为 button_add_x.xml,使用方法如下: <ImageButton 3.采用Drawable的颜色过滤: /**
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
//更改为按下时的背景图片
v.setBackgroundResource(R.drawable.pressed);
}else if(event.getAction() == MotionEvent.ACTION_UP){
//改为抬起时的图片
v.setBackgroundResource(R.drawable.released);
}
return false;
}
});
<selector xmlns:android="http://schemas.android.com/apk/res/android ">
<item android:state_pressed="false" android:drawable="@drawable/button_add" />
<item android:state_pressed="true" android:drawable="@drawable/button_add_pressed" />
<item android:state_focused="true" android:drawable="@drawable/button_add_pressed" />
<item android:drawable="@drawable/button_add" />
</selector>
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android ">
<item android:state_pressed="false" android:drawable="@drawable/button_add" />
<item android:state_pressed="true" android:drawable="@drawable/button_add_pressed" />
<item android:state_focused="true" android:drawable="@drawable/button_add_pressed" />
<item android:drawable="@drawable/button_add" />
</selector>
android:id="@+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="@drawable/button_add_x" >
</ImageButton>
<ImageButton
android:id="@+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:src="@drawable/button_add_x" >
</ImageButton>
* 按下这个按钮进行的颜色过滤
*/
public final static float[] BT_SELECTED=new float[] {
2, 0, 0, 0, 2,
0, 2, 0, 0, 2,
0, 0, 2, 0, 2,
0, 0, 0, 1, 0 };
/**
* 按钮恢复原状的颜色过滤
*/
public final static float[] BT_NOT_SELECTED=new float[] {
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0 };
/**
* 按钮焦点改变
*/
public final static OnFocusChangeListener buttonOnFocusChangeListener=new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
else
{
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
}
};
/**
* 按钮触碰按下效果
*/
public final static OnTouchListener buttonOnTouchListener=new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
else if(event.getAction() == MotionEvent.ACTION_UP){
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
return false;
}
};
/**
* 设置图片按钮获取焦点改变状态
* @param inImageButton
*/
public final static void setButtonFocusChanged(View inView)
{
inView.setOnTouchListener(buttonOnTouchListener);
inView.setOnFocusChangeListener(buttonOnFocusChangeListener);
}
/**
* 按下这个按钮进行的颜色过滤
*/
public final static float[] BT_SELECTED=new float[] {
2, 0, 0, 0, 2,
0, 2, 0, 0, 2,
0, 0, 2, 0, 2,
0, 0, 0, 1, 0 };
/**
* 按钮恢复原状的颜色过滤
*/
public final static float[] BT_NOT_SELECTED=new float[] {
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0 };
/**
* 按钮焦点改变
*/
public final static OnFocusChangeListener buttonOnFocusChangeListener=new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
else
{
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
}
};
/**
* 按钮触碰按下效果
*/
public final static OnTouchListener buttonOnTouchListener=new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
else if(event.getAction() == MotionEvent.ACTION_UP){
v.getBackground().setColorFilter(new ColorMatrixColorFilter(BT_NOT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
return false;
}
};
/**
* 设置图片按钮获取焦点改变状态
* @param inImageButton
*/
public final static void setButtonFocusChanged(View inView)
{
inView.setOnTouchListener(buttonOnTouchListener);
inView.setOnFocusChangeListener(buttonOnFocusChangeListener);
}
发表评论
-
service学习
2012-05-16 00:41 850http://www.cnblogs. ... -
InputStream,String,File相互转化
2012-05-14 23:32 12491. String --> InputStream ... -
转:实现类似手机QQ的可折叠固定标题列表
2012-04-12 19:05 1366http://douzifly.cnblog ... -
转:[Android]倒影效果的ImagView
2012-04-06 23:29 1352本文源自:http://blog.csdn.net/ke ... -
转:JDK中的URLConnection参数详解
2012-04-06 23:01 1154针对JDK中的URLConnection连 ... -
转:Game Engines for Android (Android游戏引擎)
2012-03-24 13:12 2694With Google IO fast approach ... -
做Android 系统/应用开发怎么可以不懂自动化测试
2012-03-22 15:02 1118http://blog.csdn.net/yiyaaixuex ... -
让Qt应用程序跑在Android上
2012-03-22 14:55 1325http://blog.c ... -
转:在android 2.3 AVD 模拟器上安装 google market 安卓市场
2012-03-22 14:29 1054http:// ... -
增加 addDataScheme("file") 才能收到SD卡插拔事件的原因分析 -- 浅析android事件过滤策略
2012-03-22 14:26 1927... -
转:andengine中的ParticleSystem
2012-01-18 11:08 1504看ParticleSystemSimpleExample,看得 ... -
test4:腾讯
2011-12-26 20:27 2www.qq.com -
test3:Yahoo
2011-12-26 20:25 2www.yahoo.com -
test2:google
2011-12-26 10:53 5www.google.com.hk -
test1:百度
2011-12-26 10:52 6www.baidu.com -
转:android 打包自己的自定义组件成JAR包
2011-12-24 11:54 1253http://www.cnblogs.c ... -
转:AndEngine中的字体加载及应用
2011-12-15 15:39 1521AndEngine中的字体加载及应用 An ... -
转:Android游戏框架AndEngine使用入门
2011-12-13 14:24 1560项目站点:http://www.andengine.org 项 ... -
转:notification更新数字的显示及AnimationDrawable的结合使用
2011-12-07 10:25 2581这是本人加入博客园的首篇博文,自己平常在工作学习过程遇 ... -
转:Android系统上(mv不可用)cp命令的替代方法
2011-11-30 18:32 9634Android系统上cp命令 ...
相关推荐
安卓Android源码——ImageButton.rar
Android2.2 API中文文档——ImageButton.doc
安卓Android源码——(ImageButton图片按钮).zip
安卓Android源码——(ImageButton图片按钮).rar
Android2.2 API 中文文档,注意这里只有ImageButton的,请关注http://over140.cnblogs.com/的更新。
从ImageButton这个字面意思上来看,它是一个图片按钮,那么我们就可以使用它做一个我们想要的图片按钮了,但是我们在实际使用的过程当中,就会发现该按钮的使用并没有想像中的那么简单,需要再增加一些代码或再配置...
android下imagebutton图片按下弹上可换图片哦!
android 开发中的高级控件,ImageButton网上资源视频教程源码
Android ImageButton图片按钮Demo源码.rar
Android自定义view,实现带文字的ImageButton
NULL 博文链接:https://sarin.iteye.com/blog/1673997
android ImageButton的使用,有源码解析的
android imagebutton点击变化 源码
ImageButton按下切换图片.rar ImageButton按下切换图片.rar ImageButton按下切换图片.rar
Android4.0开发学习之ImageButton的实际运行代码实例,具体描述请访问我的博客http://blog.csdn.net/lerence
Android开发实例——ImageButton源代码,图像修饰按钮的一个例子,Andorid手机上的程序界面设计都挺漂亮,这一个ImageButton也是很不错的例子。例子中包括所用到的图像资源,很不错。
使用Button时为了让用户有“按下”的效果,有两种实现方式:1.在代码里面。 代码如下:imageButton.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { ...
android 具有背景图片的按钮 ImageButton的焦点事件以及事件处理
主要介绍了 Android 点击ImageButton时有“按下”的效果的实现的相关资料,需要的朋友可以参考下