public class mainactivity extends activity
package com.example.togglebuttoncustomdemo;
import android.content.context;
import android.graphics.bitmap;
import android.graphics.bitmapfactory;
import android.graphics.canvas;
import android.util.attributeset;
import android.view.motionevent;
import android.view.view;
public class toogglebuttoncustom extends view
/*** xml布局檔案中使用
* * @param context
* @param attrs
*/public toogglebuttoncustom(context context, attributeset attrs)
/*** 有style資源檔案時使用
* * @param context
* @param attrs
* @param defstyle
*/public toogglebuttoncustom(context context, attributeset attrs, int defstyle)
/*** 設定背景
* * @param switchbackground
*/public void setbackgroundpic(int switchbackground)
/*** 設定前邊
* * @param slidebuttonbackground
*/public void setforepic(int slidebuttonbackground)
/*** 設定開關狀態
* * @param b
*/public void setstate(boolean b)
/*** 測量控制項的寬高
*/@override
protected void onmeasure(int widthmeasurespec, int heightmeasurespec)
/*** 繪製控制項
*/@override
protected void ondraw(canvas canvas) else if (left > backbitmap.getwidth() - forebitmap.getwidth())
canvas.drawbitmap(forebitmap, left, 0, null);
}else else }}
/*** 觸控控制項時呼叫的方法
*/@override
public boolean ontouchevent(motionevent event)
invalidate();//重複繪製控制項 自動呼叫ondraw()
return true;// 自己處理觸控事件}}
Android 返回按鈕的自定義設定
程式中我們有時候想讓放回按鈕按照自己的需求調整頁面而不是單純的按照系統返回上一級,這個問題很簡單,重寫onkeydown方法即可。override public boolean onkeydown int keycode,keyevent event 普通頁面的單雙擊事件設定,這裡是雙擊退出程式的設...
Android 自定義按鈕
將按鈕的背景顏色設定成drawable檔案即可。雖然這裡講的是button,但是textview及其子元件也可以如法炮製 主布局檔案如下 下面三個檔案都放在drawable hdpi資料夾下,第乙個是my button selector.xml,定義了按鈕的不同狀態 my button presse...
FckEditor自定義按鈕
fckeditor自定義按鈕 1目錄2 修訂歷史紀錄 3 1 fckeditor簡介 4 2 使用fckeditor4 3 新增自定義按鈕4 一款比較好的網頁文字編輯器 2.請設定資料夾的user使用者的訪問許可權 3.在web.config中新增 4.新增對fredck.fckeditorv2.d...