i having trouble using new material design toolbar in support library on preference screen.
i have settings.xml file below:
<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>
the strings defined elsewhere.
you can use preferencefragment
, alternative preferenceactivity
. so, here wrapping activity
example:
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(); } }
and here layout file (pref_with_actionbar):
<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>
and preferencefragment
:
public static class mypreferencefragment extends preferencefragment{ @override public void oncreate(final bundle savedinstancestate){ super.oncreate(savedinstancestate); addpreferencesfromresource(r.xml.settings); } }
i hope helps someone.
Comments
Post a Comment