我想在操作栏上放回按钮(标题) [英] I want to put back button on action bar (header)
本文介绍了我想在操作栏上放回按钮(标题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我添加这是menu.xml文件,但它没有在我的标题中显示我的后退按钮。请指导我
我尝试过:
< item>
android:id =@ + id / action_back
android:icon =@ drawable / ic_launcher
android:title =@ string / action_back
android:showAsAction =never/>
i add this is menu.xml file but it not show me back button in my header.please guide me
What I have tried:
<item>
android:id="@+id/action_back"
android:icon="@drawable/ic_launcher"
android:title="@string/action_back"
android:showAsAction="never"/>
推荐答案
这就是我解决问题的方法。
在 setContentView 之后添加这三行
This is how I solve the problem.
Add these three line after setContentView
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
并且还添加此代码
And also add this code
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
// create new file
}
return super.onOptionsItemSelected(item);
}
这篇关于我想在操作栏上放回按钮(标题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文