WEB开发网
开发学院手机开发Android 开发 在android的状态栏(statusbar)中增加menu,home和... 阅读

在android的状态栏(statusbar)中增加menu,home和back快捷键的方法

 2010-09-15 00:01:00 来源:WEB开发网   
核心提示:1.添加各个图片按钮的引用,android.widget.LinearLayout keysLayout;android.widget.ImageView btnHome;android.widget.ImageView btnBack;android.widget.ImageView btnMenu;android.

1.添加各个图片按钮的引用,

android.widget.LinearLayout keysLayout;

android.widget.ImageView btnHome;

android.widget.ImageView btnBack;

android.widget.ImageView btnMenu;

android.widget.ImageView btnVolUp;

android.widget.ImageView btnVolDown;

2.修改onFinishInflate()函数,各个图片ID在上面的status_bar.xml中已经定义

@Override

protected void onFinishInflate() {

......

/* Begin : Added by TigerPan */

keysLayout = (android.widget.LinearLayout)findViewById(R.id.keys);

btnHome = (android.widget.ImageView)findViewById(R.id.status_home);

btnBack = (android.widget.ImageView)findViewById(R.id.status_back);

btnMenu = (android.widget.ImageView)findViewById(R.id.status_menu);

btnVolUp = (android.widget.ImageView)findViewById(R.id.status_vol_up);

btnVolDown = (android.widget.ImageView)findViewById(R.id.status_vol_down);

btnHome.setOnClickListener(mKeysListener);

btnBack.setOnClickListener(mKeysListener);

btnMenu.setOnClickListener(mKeysListener);

btnVolUp.setOnClickListener(mKeysListener);

btnVolDown.setOnClickListener(mKeysListener);

/* End : Added by TigerPan */

}

3.添加各个按钮的事件监听Listener

android.view.View.OnClickListener mKeysListener = new android.view.View.OnClickListener(){

public void onClick(View v) {

switch (v.getId()) {

case R.id.status_home:

mKeysHandler.sendEmptyMessage(KEY_HOME);

break;

case R.id.status_back:

mKeysHandler.sendEmptyMessage(KEY_BACK);

break;

case R.id.status_menu:

mKeysHandler.sendEmptyMessage(KEY_MENU);

break;

case R.id.status_vol_up:

mKeysHandler.sendEmptyMessage(KEY_VOL_UP);

上一页  1 2 3 4 5 6  下一页

Tags:android 状态 statusbar

编辑录入:coldstar [复制链接] [打 印]
赞助商链接