Merge pull request #199 from Poslovitch/appbar-settings-activity

Added appbar at the top of the SettingsActivity
This commit is contained in:
Stefan Schüller 2020-07-04 19:39:27 +02:00 committed by GitHub
commit b9d6aff740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -38,12 +38,25 @@ public class SettingsActivity extends CommonActivity {
.beginTransaction() .beginTransaction()
.replace(R.id.settings, new SettingsFragment()) .replace(R.id.settings, new SettingsFragment())
.commit(); .commit();
// Attaching the layout to the toolbar object
Toolbar toolbar = findViewById(R.id.tool_bar_settings);
// Setting toolbar as the ActionBar with setSupportActionBar() call
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
if (actionBar != null) { if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_baseline_close_24);
} }
} }
@Override
public boolean onSupportNavigateUp() {
finish(); // close this activity as oppose to navigating up
return false;
}
public static class SettingsFragment extends PreferenceFragmentCompat { public static class SettingsFragment extends PreferenceFragmentCompat {
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

View File

@ -1,6 +1,21 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar_settings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp" />
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout <FrameLayout
android:id="@+id/settings" android:id="@+id/settings"