Android 应用程序栏中的“后退”按钮
我想问一下如何将“后退”按钮添加到应用程序栏 我的应用程序栏如下所示: 但我想把这个箭头放在我的应用程序栏标题之前 这是my Styles.xmlAndroid 应用程序栏中的“后退”按钮,android,android-layout,Android,Android Layout,我想问一下如何将“后退”按钮添加到应用程序栏 我的应用程序栏如下所示: 但我想把这个箭头放在我的应用程序栏标题之前 这是my Styles.xml <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
假的
真的
有人能帮我吗?如果您使用的是
工具栏
,它非常简单
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
将此代码添加到要显示“后退”按钮的活动中
//onCreate
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle("title");
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
“OnOptions ItemSelected(MenuItem)”不在onCreate中!就在onCreate之下