WEB开发网
开发学院手机开发Android 开发 Android标题栏TitleBar全攻略 阅读

Android标题栏TitleBar全攻略

 2010-08-20 01:57:00 来源:WEB开发网   
核心提示:Resources resources = context.getResources();mCircularProgress = (Drawable) resources.getDrawable(com.android.internal.R.drawable.search_spinner);mIconDimension

Resources resources = context.getResources();

mCircularProgress = (Drawable) resources.getDrawable(com.android.internal.R.drawable.search_spinner);

mIconDimension = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20f,resources.getDisplayMetrics());

mCircularProgress.setBounds(0, 0, mIconDimension, mIconDimension);

mHorizontalProgress = (ProgressBar) findViewById(R.id.progress_horizontal);

mGenericFavicon = context.getResources().getDrawable(R.drawable.app_web_browser_sm);

}

private class MyHandler extends Handler {

public void handleMessage(Message msg) {

if (msg.what == LONG_PRESS) {

mTitleBg.setPressed(false);

mBrowserActivity.showTitleBarContextMenu();

}

}

};

@Override

protected void onCreateContextMenu(ContextMenu menu) { //创建上下文菜单,相关的xml代码在本文最后

MenuInflater inflater = mBrowserActivity.getMenuInflater();

inflater.inflate(R.menu.title_context, menu);

}

@Override

public boolean onTouchEvent(MotionEvent event) {

switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:

if ((int) event.getX() > mTitleBg.getRight()) {

mRtButton.setPressed(true);

} else {

mTitleBg.setPressed(true);

mHandler.sendMessageDelayed(mHandler.obtainMessage(

LONG_PRESS),

ViewConfiguration.getLongPressTimeout());

}

break;

case MotionEvent.ACTION_MOVE:

int slop = ViewConfiguration.get(mBrowserActivity)

.getScaledTouchSlop();

if ((int) event.getY() > getHeight() + slop) {

mTitleBg.setPressed(false);

mRtButton.setPressed(false);

mHandler.removeMessages(LONG_PRESS);

break;

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

Tags:Android 标题 TitleBar

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