我在自定义标题栏上创建主页按钮(使用图片到按钮)。 我的问题是每次点击这个按钮。它将会主要。 当停留在主页面并点击按钮。它会一次又一次地到主页。 我该怎么办? 在主页面时我不想去主要或者不能在主页面点击这个按钮。自定义标题栏上的Android主页按钮
你明白吗?
请帮我 谢谢
public class CustomTitleBar extends Activity {
protected ImageButton toHome;
protected TextView title;
protected ImageView icon;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
toHome = (ImageButton) findViewById(R.id.header);
title = (TextView) findViewById(R.id.title);
icon = (ImageView) findViewById(R.id.icon);
ProgressBar titleProgressBar = (ProgressBar) findViewById(R.id.loadProgress);
titleProgressBar.setVisibility(ProgressBar.GONE);
/* -- Button to HOME -- */
toHome.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent goHome = new Intent(Intent.ACTION_MAIN);
goHome.setClass(CustomTitleBar.this, MainActivity.class);
startActivity(goHome);
finish();
}
});
}
}
才有人告诉我用面漆();但它无法解决我的问题。
从例如:主>第1页>(点击家)>主>第2页>(点击家)>主
当移动
周期点击返回按钮是:主>第2页>主>第1页>主要>出于应用程序。
当我使用finish()后,在手机上点击返回按钮;
循环为:main> main> main> out of app。
非常感谢,但如何使用它? – 2011-06-05 15:59:53
哈哈,这是:toHome.setOnClickListener(新OnClickListener(){ 公共无效的onClick(视图v){ 意向意图=新意图(这一点,MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity (intent); finish(); } }); – anticafe 2011-06-05 16:29:03
构造函数Intent(new View.OnClickListener(){},Class)未定义.... –
2011-06-05 16:41:12