我正在构建并完成一个 Android 应用程序,这是我需要修复它的主要事情之一。
所以,我有一个样式如下的操作栏:
<resources>
<style name="MyCustomTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#F6E6E7</item>
<item name="android:textSize">10sp</item>
</style>
<style name="CustomTabWidget">
<item name="android:textSize">15sp</item>
</style>
</resources>
这是我放置按钮的布局
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="@+id/voltar"
android:title="Voltar"
android:icon="@drawable/abc_ic_ab_back_holo_light"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
</menu>
这个标题为 Voltar 的按钮位于操作栏的右侧。我应该怎么做才能将它放在左侧?
感谢您阅读本文
最佳答案
你需要做两件事。首先在您的 Activity 的 onCreate
中声明它
getActionBar().setDisplayHomeAsUpEnabled(true);
然后实现 onOptionsItemSelected
以将 home 处理为向上按钮点击事件
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home ) {
finish();
return true;
}
// other menu select events may be present here
return super.onOptionsItemSelected(item);
}
关于android - 如何将后退按钮放在 ActionBar 的左侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27193388/