【发布时间】:2015-11-23 22:24:55
【问题描述】:
我正在尝试创建一个工具栏,该工具栏也有主页图标/按钮,以便用户可以带着它回家。
这是我的代码:
AndroidManifest.xml
<activity
android:name=".SettingsActivity"
android:noHistory="true"
android:theme="@style/AppTheme">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
工具栏.xml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/ColorPrimary"
android:elevation="2dp"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"/>
settings_activity.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/tool_bar"
layout="@layout/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout
SettingsActivity.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
但是我看到的只是我的应用程序的名称,根本没有 UP/Home 按钮?
你能帮帮我吗
【问题讨论】:
标签: android xml android-actionbar toolbar