Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
- <PreferenceCategory
- android:title="@string/AddingItems"
- android:key="pref_key_storage_settings">
- <ListPreference
- android:key="pref_key_new_items"
- android:title="@string/LocationOfNewItems"
- android:summary="@string/LocationOfNewItemsSummary"
- android:entries="@array/new_items_entry"
- android:entryValues="@array/new_item_entry_value"
- android:defaultValue="1"/>
- </PreferenceCategory>
- </PreferenceScreen>
- public class MyPreferenceActivity extends ActionBarActivity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.pref_with_actionbar);
- android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(uk.japplications.jcommon.R.id.toolbar);
- setSupportActionBar(toolbar);
- getFragmentManager().beginTransaction().replace(R.id.content_frame, new MyPreferenceFragment()).commit();
- }
- }
- <RelativeLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_height="@dimen/action_bar_height"
- android:layout_width="match_parent"
- android:minHeight="?attr/actionBarSize"
- android:background="?attr/colorPrimary"
- app:theme="@style/ToolbarTheme.Base"
- app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
- <FrameLayout
- android:id="@+id/content_frame"
- android:layout_below="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- </RelativeLayout>
- public static class MyPreferenceFragment extends PreferenceFragment{
- @Override
- public void onCreate(final Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.settings);
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.v7.widget.Toolbar
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:id="@+id/toolbar"
- app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?attr/actionBarSize"
- app:navigationContentDescription="@string/abc_action_bar_up_description"
- android:background="?attr/colorPrimary"
- app:navigationIcon="?attr/homeAsUpIndicator"
- app:title="@string/action_settings"
- />
- public class SettingsActivity extends PreferenceActivity {
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent();
- Toolbar bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
- root.addView(bar, 0); // insert at top
- bar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- }
- }
- LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent();
- public class SettingsActivity extends PreferenceActivity {
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- Toolbar bar;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
- bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
- root.addView(bar, 0); // insert at top
- } else {
- ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
- ListView content = (ListView) root.getChildAt(0);
- root.removeAllViews();
- bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
- int height;
- TypedValue tv = new TypedValue();
- if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
- height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
- }else{
- height = bar.getHeight();
- }
- content.setPadding(0, height, 0, 0);
- root.addView(content);
- root.addView(bar);
- }
- bar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- }
- }
- import android.support.v7.internal.widget.TintCheckBox;
- import android.support.v7.internal.widget.TintCheckedTextView;
- import android.support.v7.internal.widget.TintEditText;
- import android.support.v7.internal.widget.TintRadioButton;
- import android.support.v7.internal.widget.TintSpinner;
- @Override
- public View onCreateView(String name, Context context, AttributeSet attrs) {
- // Allow super to try and create a view first
- final View result = super.onCreateView(name, context, attrs);
- if (result != null) {
- return result;
- }
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
- // If we're running pre-L, we need to 'inject' our tint aware Views in place of the
- // standard framework versions
- switch (name) {
- case "EditText":
- return new TintEditText(this, attrs);
- case "Spinner":
- return new TintSpinner(this, attrs);
- case "CheckBox":
- return new TintCheckBox(this, attrs);
- case "RadioButton":
- return new TintRadioButton(this, attrs);
- case "CheckedTextView":
- return new TintCheckedTextView(this, attrs);
- }
- }
- return null;
- }
- @Override
- public View onCreateView(String name, Context context, AttributeSet attrs) {
- // Allow super to try and create a view first
- final View result = super.onCreateView(name, context, attrs);
- if (result != null) {
- return result;
- }
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
- // If we're running pre-L, we need to 'inject' our tint aware Views in place of the
- // standard framework versions
- switch (name) {
- case "EditText":
- return new AppCompatEditText(this, attrs);
- case "Spinner":
- return new AppCompatSpinner(this, attrs);
- case "CheckBox":
- return new AppCompatCheckBox(this, attrs);
- case "RadioButton":
- return new AppCompatRadioButton(this, attrs);
- case "CheckedTextView":
- return new AppCompatCheckedTextView(this, attrs);
- }
- }
- return null;
- }
- @SuppressWarnings("deprecation")
- @Override
- public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
- super.onPreferenceTreeClick(preferenceScreen, preference);
- // If the user has clicked on a preference screen, set up the screen
- if (preference instanceof PreferenceScreen) {
- setUpNestedScreen((PreferenceScreen) preference);
- }
- return false;
- }
- public void setUpNestedScreen(PreferenceScreen preferenceScreen) {
- final Dialog dialog = preferenceScreen.getDialog();
- Toolbar bar;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
- LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
- bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
- root.addView(bar, 0); // insert at top
- } else {
- ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content);
- ListView content = (ListView) root.getChildAt(0);
- root.removeAllViews();
- bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
- int height;
- TypedValue tv = new TypedValue();
- if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
- height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
- }else{
- height = bar.getHeight();
- }
- content.setPadding(0, height, 0, 0);
- root.addView(content);
- root.addView(bar);
- }
- bar.setTitle(preferenceScreen.getTitle());
- bar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- dialog.dismiss();
- }
- });
- }
- <android.support.design.widget.AppBarLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <android.support.v7.widget.Toolbar
- .../>
- </android.support.design.widget.AppBarLayout>
- compile 'com.android.support:support-v4:22.2.0'
- compile 'com.android.support:appcompat-v7:22.2.0'
- compile 'com.android.support:design:22.2.0'
- public class SettingsActivity extends AppCompatPreferenceActivity {
- @Override
- public void onBuildHeaders(List<Header> target) {
- loadHeadersFromResource(R.xml.settings, target);
- setContentView(R.layout.settings_page);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- ActionBar bar = getSupportActionBar();
- bar.setHomeButtonEnabled(true);
- bar.setDisplayHomeAsUpEnabled(true);
- bar.setDisplayShowTitleEnabled(true);
- bar.setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
- bar.setTitle(...);
- }
- @Override
- protected boolean isValidFragment(String fragmentName) {
- return SettingsFragment.class.getName().equals(fragmentName);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- onBackPressed();
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_margin="0dp"
- android:orientation="vertical"
- android:padding="0dp">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize"
- android:background="?attr/colorPrimary"
- android:elevation="4dp"
- android:theme="@style/..."/>
- <ListView
- android:id="@id/android:list"
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
- </LinearLayout>
- <preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
- <header
- android:fragment="com.example.SettingsFragment"
- android:summary="@string/..."
- android:title="@string/...">
- <extra
- android:name="page"
- android:value="page1"/>
- </header>
- <header
- android:fragment="com.example.SettingsFragment"
- android:summary="@string/..."
- android:title="@string/...">
- <extra
- android:name="page"
- android:value="page2"/>
- </header>
- ...
- </preference-headers>
- public class SettingsFragment extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getActivity().setTheme(R.style...);
- if (getArguments() != null) {
- String page = getArguments().getString("page");
- if (page != null)
- switch (page) {
- case "page1":
- addPreferencesFromResource(R.xml.settings_page1);
- break;
- case "page2":
- addPreferencesFromResource(R.xml.settings_page2);
- break;
- ...
- }
- }
- }
- @Override
- public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View layout = inflater.inflate(R.layout.settings_page, container, false);
- if (layout != null) {
- AppCompatPreferenceActivity activity = (AppCompatPreferenceActivity) getActivity();
- Toolbar toolbar = (Toolbar) layout.findViewById(R.id.toolbar);
- activity.setSupportActionBar(toolbar);
- ActionBar bar = activity.getSupportActionBar();
- bar.setHomeButtonEnabled(true);
- bar.setDisplayHomeAsUpEnabled(true);
- bar.setDisplayShowTitleEnabled(true);
- bar.setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
- bar.setTitle(getPreferenceScreen().getTitle());
- }
- return layout;
- }
- @Override
- public void onResume() {
- super.onResume();
- if (getView() != null) {
- View frame = (View) getView().getParent();
- if (frame != null)
- frame.setPadding(0, 0, 0, 0);
- }
- }
- }
- import android.support.v7.widget.Toolbar;
- public class MyPreferenceActivity extends PreferenceActivity
- Toolbar mToolbar;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
- LinearLayout content = (LinearLayout) root.getChildAt(0);
- LinearLayout toolbarContainer = (LinearLayout) View.inflate(this, R.layout.activity_settings, null);
- root.removeAllViews();
- toolbarContainer.addView(content);
- root.addView(toolbarContainer);
- mToolbar = (Toolbar) toolbarContainer.findViewById(R.id.toolbar);
- }
- @Override
- public void onBuildHeaders(List<Header> target) {
- loadHeadersFromResource(R.xml.pref_headers, target);
- }
- // Other methods
- }
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_height="?attr/actionBarSize"
- android:layout_width="match_parent"
- android:minHeight="?attr/actionBarSize"
- android:background="?attr/colorPrimary"
- app:theme="@style/AppTheme"
- app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
- </LinearLayout>
- <preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
- <header
- android:fragment="com.example.FirstFragment"
- android:title="@string/pref_header_first" />
- <header
- android:fragment="com.example.SecondFragment"
- android:title="@string/pref_header_second" />
- </preference-headers>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/app_theme_light"
- app:popupTheme="@style/Theme.AppCompat.Light"
- app:theme="@style/Theme.AppCompat" />
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:padding="@dimen/padding_medium" >
- <ListView
- android:id="@android:id/list"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- </FrameLayout>
- public class SettingsActivity extends PreferenceActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_settings);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- addPreferencesFromResource(R.xml.preferences);
- toolbar.setClickable(true);
- toolbar.setNavigationIcon(getResIdFromAttribute(this, R.attr.homeAsUpIndicator));
- toolbar.setTitle(R.string.menu_settings);
- toolbar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- }
- private static int getResIdFromAttribute(final Activity activity, final int attr) {
- if (attr == 0) {
- return 0;
- }
- final TypedValue typedvalueattr = new TypedValue();
- activity.getTheme().resolveAttribute(attr, typedvalueattr, true);
- return typedvalueattr.resourceId;
- }
- }
- public void setSupportActionBar(@Nullable Toolbar toolbar) {
- getDelegate().setSupportActionBar(toolbar);
- ActionBar bar = getDelegate().getSupportActionBar();
- bar.setHomeButtonEnabled(true);
- bar.setDisplayHomeAsUpEnabled(true);
- }
- abstract class AppCompatPreferenceFragment extends PreferenceFragment {
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.activity_settings, container, false);
- if (view != null) {
- Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar_settings);
- ((AppCompatPreferenceActivity) getActivity()).setSupportActionBar(toolbar);
- }
- return view;
- }
- @Override
- public void onResume() {
- super.onResume();
- View frame = (View) getView().getParent();
- if (frame != null) frame.setPadding(0, 0, 0, 0);
- }
- }
- public class SettingsActivity extends AppCompatPreferenceActivity {
- boolean mAttachedFragment;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- mAttachedFragment = false;
- super.onCreate(savedInstanceState);
- }
- @Override
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public void onBuildHeaders(List<Header> target) {
- loadHeadersFromResource(R.xml.pref_headers, target);
- }
- @Override
- public void onAttachFragment(Fragment fragment) {
- mAttachedFragment = true;
- super.onAttachFragment(fragment);
- }
- @Override
- protected void onPostCreate(Bundle savedInstanceState) {
- super.onPostCreate(savedInstanceState);
- //if we didn't attach a fragment, go ahead and apply the layout
- if (!mAttachedFragment) {
- setContentView(R.layout.activity_settings);
- setSupportActionBar((Toolbar)findViewById(R.id.toolbar_settings));
- }
- }
- /**
- * This fragment shows general preferences only. It is used when the
- * activity is showing a two-pane settings UI.
- */
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
- public static class GeneralPreferenceFragment extends AppCompatPreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.pref_general);
- setHasOptionsMenu(true);
- bindPreferenceSummaryToValue(findPreference("example_text"));
- bindPreferenceSummaryToValue(findPreference("example_list"));
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int id = item.getItemId();
- if (id == android.R.id.home) {
- startActivity(new Intent(getActivity(), SettingsActivity.class));
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <include
- layout="@layout/app_bar_settings"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.design.widget.CoordinatorLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/content_frame"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:fitsSystemWindows="true"
- tools:context=".SettingsActivity">
- <android.support.design.widget.AppBarLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:theme="@style/AppTheme.NoActionBar.AppBarOverlay">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar_settings"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize"
- android:background="?attr/colorPrimary"
- app:popupTheme="@style/AppTheme.NoActionBar.PopupOverlay" />
- </android.support.design.widget.AppBarLayout>
- <include layout="@layout/content_settings" />
- </android.support.design.widget.CoordinatorLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/content"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- app:layout_behavior="@string/appbar_scrolling_view_behavior"
- tools:context=".SettingsActivity"
- tools:showIn="@layout/app_bar_settings">
- <ListView
- android:id="@android:id/list"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- </RelativeLayout>
- import android.support.design.widget.AppBarLayout;
- import android.support.v4.app.NavUtils;
- import android.support.v7.widget.Toolbar;
- private void setupActionBar() {
- Toolbar toolbar = new Toolbar(this);
- AppBarLayout appBarLayout = new AppBarLayout(this);
- appBarLayout.addView(toolbar);
- final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
- final ViewGroup window = (ViewGroup) root.getChildAt(0);
- window.addView(appBarLayout, 0);
- setSupportActionBar(toolbar);
- // Show the Up button in the action bar.
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- toolbar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- onBackPressed();
- }
- });
- }
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="com.my.package">
- <android.support.v7.widget.Toolbar
- android:id="@+id/tool_bar"
- android:layout_width="match_parent"
- android:layout_height="?attr/actionBarSize"
- android:background="?attr/colorPrimary"
- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
- app:elevation="@dimen/appbar_elevation"
- app:navigationIcon="?attr/homeAsUpIndicator"
- app:navigationContentDescription="@string/abc_action_bar_up_description"
- app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
- <ListView
- android:id="@android:id/list"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/tool_bar" />
- </RelativeLayout>
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_settings);
- Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
- toolbar.setTitle(R.string.action_settings);
- toolbar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- finish();
- }
- });
- }
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent" android:layout_height="match_parent"
- android:fitsSystemWindows="true" tools:context="edu.adelphi.Adelphi.ui.activity.MainActivity">
- <android.support.design.widget.AppBarLayout android:id="@+id/appbar"
- android:layout_width="match_parent" android:layout_height="wrap_content"
- android:theme="@style/AppTheme.AppBarOverlay">
- <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"/>
- </android.support.design.widget.AppBarLayout>
- <FrameLayout android:id="@+id/content"
- android:layout_width="match_parent" android:layout_height="match_parent"/>
- </android.support.design.widget.CoordinatorLayout>
- @Override
- public void setContentView(@LayoutRes int layoutResID) {
- View view = getLayoutInflater().inflate(R.layout.toolbar, null);
- FrameLayout content = (FrameLayout) view.findViewById(R.id.content);
- getLayoutInflater().inflate(layoutResID, content, true);
- setContentView(view);
- }
- private void setupActionBar() {
- Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
- //Toolbar will now take on default Action Bar characteristics
- setSupportActionBar(toolbar);
- getSupportActionBar().setHomeButtonEnabled(true);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- onBackPressed();
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- @Override
- public void onBackPressed() {
- if (getFragmentManager().getBackStackEntryCount() > 0) {
- getFragmentManager().popBackStackImmediate();
- //If the last fragment was removed then reset the title of main
- // fragment (if so the previous popBackStack made entries = 0).
- if (getFragmentManager().getBackStackEntryCount() == 0) {
- getSupportActionBar()
- .setTitle(R.string.action_settings_title);
- }
- } else {
- super.onBackPressed();
- }
- }
- <activity
- android:name=".Dashboard.PreferencepActivity"
- android:label="@string/title_activity_preference"
- android:theme="@style/Pref"></activity>
- <style name="Pref" parent="Theme.AppCompat.DayNight.DarkActionBar">
- <!-- Customize your theme here. -->
- <item name="colorPrimary">@color/colorPrimary</item>
- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
- <item name="colorAccent">@color/colorAccent</item>
- </style>
Add Comment
Please, Sign In to add comment