Search code examples
androidandroid-4.0-ice-cream-sandwichandroid-homebutton

How to set app title as up in Android 4.0 & 4.1


I have an app which should work on android 4.0 and up. When I try the app with my Samsung Galaxy S5 (Android 4.4.2), everything looks fine. I can press the activitie's title to go back. But on Android 4.0 and Android 4.1, I can only press the arrow left to the activie's title. But the title should be clickable, too. How can I do this?

In the activiy, I call this:

public void onCreate(Bundle savedInstanceState) {
     ActionBar actionBar = getActionBar();
     actionBar.setDisplayHomeAsUpEnabled(true);
     actionBar.setTitle(R.string.txt_publication_back);
}

And the relevant part of the AndroidManifest looks like this:

  <activity
            android:name="views.activies.EditionActivity"
            android:label="@string/txt_window_editions"
            android:parentActivityName=".views.activies.MainActivity">
        <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".views.activies.MainActivity"/>

    </activity>

Any help would be appreciated! Thank you!


Solution

  • logically it should work until and unless you have specify some thing like code below.

        getActionBar().setDisplayShowCustomEnabled(true);
        getActionBar().setCustomView(R.layout.custom_actionbar);
    

    Here the title is not clickable but in ur case I am not able to get. Still with workaround we can achieve

    int actionBarTitleID = getResources().getIdentifier("action_bar_title", "id", "android");
    findViewById(actionBarTitleID).setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v) {
            // do ur logic
        }
    });
    

    I don't know exactly how much it can help you...