亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2014年03月16日 09:17:37   作者:  
由于項目這種類型的圖片按鈕比較多,所以重寫了ImageButton類,現(xiàn)在把代碼分享給大家,需要的朋友可以參考下

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

復制代碼 代碼如下:

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;
 }
}

布局文件

復制代碼 代碼如下:

<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" />

相關文章

  • Android巧用ViewPager實現(xiàn)左右循環(huán)滑動圖片

    Android巧用ViewPager實現(xiàn)左右循環(huán)滑動圖片

    這篇文章主要為大家詳細介紹了Android巧用ViewPager實現(xiàn)左右循環(huán)滑動圖片的相關資料,感興趣的小伙伴們可以參考一下
    2016-05-05
  • Android中使用ListView實現(xiàn)漂亮的表格效果

    Android中使用ListView實現(xiàn)漂亮的表格效果

    這篇文章主要介紹了Android中使用ListView實現(xiàn)漂亮的表格效果,本文用詳細的代碼實例創(chuàng)建了一個股票行情表格,需要的朋友可以參考下
    2014-10-10
  • Android開發(fā)之自定義CheckBox

    Android開發(fā)之自定義CheckBox

    本文通過實例代碼演示如何在Android中如何自定義CheckBox,實現(xiàn)的效果很好,有需要的可以參考借鑒。
    2016-08-08
  • Android之FanLayout制作圓弧滑動效果

    Android之FanLayout制作圓弧滑動效果

    這篇文章主要介紹了Android之FanLayout制作圓弧滑動效果,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-08-08
  • Android實現(xiàn)志愿者系統(tǒng)詳細步驟與代碼

    Android實現(xiàn)志愿者系統(tǒng)詳細步驟與代碼

    這篇文章主要介紹了Android實現(xiàn)志愿者系統(tǒng),本系統(tǒng)采用MVC架構設計,SQLite數(shù)據(jù)表有用戶表、成員表和活動表,有十多個Activity頁面。打開應用,進入歡迎界面,3s后跳轉登錄界面,用戶先注冊賬號,登錄成功后進入主界面
    2023-02-02
  • android實用工具類分享(獲取內(nèi)存/檢查網(wǎng)絡/屏幕高度/手機分辨率)

    android實用工具類分享(獲取內(nèi)存/檢查網(wǎng)絡/屏幕高度/手機分辨率)

    這篇文章主要介紹了android實用工具類,包括獲取內(nèi)存、檢查網(wǎng)絡、屏幕高度、手機分辨率、獲取版本號等功能,需要的朋友可以參考下
    2014-03-03
  • 淺談Android ANR的信息收集過程

    淺談Android ANR的信息收集過程

    ANR全稱即Application Not Responding,也就是應用程序無響應。這篇文章主要介紹了Android ANR的信息收集過程,感興趣的同學可以了解一下
    2021-11-11
  • Flutter開發(fā)中的路由參數(shù)處理

    Flutter開發(fā)中的路由參數(shù)處理

    在實際開發(fā)中,我們經(jīng)常會需要在頁面跳轉的時候攜帶路由參數(shù),典型的例子就是從列表到詳情頁的時候,需要攜帶詳情的 id,以便詳情頁獲取對應的數(shù)據(jù)。同時,有些時候還需要返回時攜帶參數(shù)返回上一級,以便上級頁面根據(jù)返回結果更新。本篇將介紹這兩種情形的實現(xiàn)。
    2021-06-06
  • Android?Flutter實現(xiàn)評分組件的示例代碼

    Android?Flutter實現(xiàn)評分組件的示例代碼

    在很多應用中,我們都需要收集用戶的評分,比如商品滿意度、配送滿意度、應用使用體驗等等。本文就利用flutter_rating_bar實現(xiàn)簡易的評分組件,感興趣的可以
    2022-11-11
  • Kotlin WorkManager使用方法詳解

    Kotlin WorkManager使用方法詳解

    這篇文章主要介紹了Kotlin WorkManager使用方法,WorkManager是 安卓體系結構之一,也是Android JetPack的一部分。WorkManager用于可延期并需要保證執(zhí)行的后臺工作
    2023-01-01

最新評論