Background
I want to show the ActionBar about PreferenceActivity, since it is not available for devices with a preliminary cell (even in the support library).
Since such a class is not available in the support library, I cannot just call "setSupportActionBar". I also do not want to use a library (like this one ), since all the libraries that I found still use the Holo style, so they have not yet been updated with that in mind.
To do this, I try to imitate the look and feel of the ActionBar name in the new Toolbar class, which was introduced in the v7 support library.
Problem
I managed to put the title and the up button, but I canβt figure out how to make them clickable, like a regular action bar, including the touch effect.
Code
Here is the code:
SettingsActivity.java
public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); addPreferencesFromResource(R.xml.pref_general); final Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar); toolbar.setBackgroundColor(getResources().getColor(R.color.windowBackgroundColor)); toolbar.setTitle("Settings"); toolbar.setClickable(true); toolbar.setLogo(getResIdFromAttribute(this,R.attr.homeAsUpIndicator)); } public 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; } }
activity_settings.xml
<LinearLayout xmlns: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" android:orientation="vertical" tools:context="com.antonioleiva.materialeverywhere.SettingsActivity" > <include android:id="@+id/toolbar" layout="@layout/toolbar" /> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" > <View android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/abs__ab_solid_shadow_holo" /> <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" /> </FrameLayout> </LinearLayout>
What i tried
I tried all types of toolbar class click listeners, but none of them helped.
The only thing that almost worked was to use "setNavigationIcon" instead of "setLogo", but it actually does a click on the title and thus only the icon shows the effect of clicking (even if I click on the title).
Question
How can I add a toolbar appearance so that the title and logo look like an ActionBar?