Toolbar In Settings Page Built With Preferencefragment
I built a Settings activity/screen for my app using this guide. Example code is bellow. What am I missing to be able to add a Toolbar to this new activity with a back arrow in it's
Solution 1:
You must include a toolbar in your activity layout. For example:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".activities.SettingsActivity"><includeandroid:id="@+id/app_bar"layout="@layout/app_bar" /><FrameLayoutandroid:id="@+id/container"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_below="@+id/app_bar"/></RelativeLayout>app_bar.xml
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
In your Activity.onCreate() get the toolbar and set a home button (the little arrow):
Toolbartoolbar= (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Set the SettingsActivity to be a child of parent MainActivity:
<activityandroid:name=".activities.SettingsActivity"android:label="@string/title_activity_main"android:parentActivityName=".activities.MainActivity" />And that will give you that little arrow.
Also, do this:
publicclassSettingsActivityextendsAppCompatActivityNot this:
publicclassSettingsActivityextendsActivityIn order to use support library.
Post a Comment for "Toolbar In Settings Page Built With Preferencefragment"