麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 系統(tǒng) > Android > 正文

android自定義按鈕示例(重寫imagebutton控件實(shí)現(xiàn)圖片按鈕)

2020-04-11 11:52:11
字體:
供稿:網(wǎng)友

由于項(xiàng)目這種類型的圖片按鈕比較多,所以重寫了ImageButton類。

復(fù)制代碼 代碼如下:

package me.henji.widget;

import android.content.Context;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;

/**
 * 自定義圖片按鈕(ImageButton),按下顏色改變
 * @author Leo
 * @created 2013-3-15
 */
public class CmButton extends ImageButton implements OnTouchListener, OnFocusChangeListener {

 public CmButton(Context context) {
  super(context);
  this.setOnTouchListener(this);
  this.setOnFocusChangeListener(this);
 }

 public CmButton(Context context, AttributeSet attrs) {
  this(context, attrs, android.R.attr.imageButtonStyle);
  this.setOnTouchListener(this);
  this.setOnFocusChangeListener(this);
 }

 public CmButton(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  setFocusable(true);
  this.setOnTouchListener(this);
  this.setOnFocusChangeListener(this);
 }

 @Override
 public void onFocusChange(View v, boolean hasFocus) {
  // 灰色效果
  ColorMatrix cm = new ColorMatrix();
  cm.setSaturation(0);
  if (hasFocus) {
   ((ImageButton) v).getDrawable().setColorFilter(new ColorMatrixColorFilter(cm));
  } else {
   ((ImageButton) v).getDrawable().clearColorFilter();
  }
 }

 @Override
 public boolean onTouch(View v, MotionEvent event) {
  // 灰色效果
  ColorMatrix cm = new ColorMatrix();
  cm.setSaturation(0);
  if (event.getAction() == MotionEvent.ACTION_DOWN) {
   ((ImageButton) v).getDrawable().setColorFilter(new ColorMatrixColorFilter(cm));
  } else if (event.getAction() == MotionEvent.ACTION_UP) {
   ((ImageButton) v).getDrawable().clearColorFilter();
  }
  return false;
 }
}

布局文件

復(fù)制代碼 代碼如下:

<me.henji.widget.CmButton
    android:id="@+id/btn_login"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#00000000"
    android:src="@drawable/button_login"
    android:text="@string/login_login" />

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产亚洲精品成人a | 久久久一区二区三区精品 | 成人在线不卡 | 黑人一级片 | 一级大黄毛片 | 久久久精品视频在线观看 | 一级精品| 亚洲片在线观看 | 男女羞羞视频在线观看免费 | 亚洲特黄妇女高潮 | 久久久久久久.comav | 色中色在线播放 | 九九热精品在线视频 | 精品国产一区二区亚洲人成毛片 | av在线1| 91精品片 | 久久蜜桃精品一区二区三区综合网 | 精品国产九九九 | 黄色二区三区 | chinese hd xxxx tube| 国产毛片在线看 | 日韩毛片在线看 | 欧美hdfree性xxxx | 国产三级在线观看a | 国产精品久久久久久久久久久久午夜 | 在线成人一区二区 | 久久影院午夜 | 1314av | 国产1级视频 | 国产视频精品在线 | 久久久久久久黄色片 | 国产精品久久久久久久久久久久久久久 | 免费播放欧美毛片 | 亚洲国产视频在线 | 国产一区二区三区四区五区在线 | 久久精品黄 | 国产成人精品无人区一区 | 日日摸夜夜骑 | 欧美日韩在线播放一区 | 精品一区二区三区免费毛片爱 | 一级毛片播放 |