0

I have 2 types of fragments between which I want to switch. Each time I create new instance of fragment I need.

In the first fragment I need to have clickable home icon so I set the appropriate (setDisplayShowHomeAsUpEnabled) display option to true and home icon starts look like an up. In the second one I don't need it so I set the appropriate display option to false and it stops looking as up. I'm listening to clicks on the action bar icon in parent activity.

The issue is that after second fragment is shown once the next time I show first fragment home icon remains clickable while it doesn't look like an up. The question is why is it clickable if currently visible fragment set it to not look like an up button?

I'm using appcompat-v7 library.

Lingviston
  • 5,479
  • 5
  • 35
  • 67

1 Answers1

0

Please set the home buttom eanabled to false as well.

 getSupportActionBar().setHomeButtonEnabled(false);

Lemme know if this works. :)

EDIT - One more way, but I am not sure on this.

You can set styles for your ActionBar title and over there you can set it as non-clickable as.

 <item name="titleTextStyle">@style/TitleTextStyle</item>

and here is TitleTextStyle,

<!-- action bar title text -->
<style name="TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/actionbar_text</item>
    <item name="android:clickable">false</item>
</style>

Remember to do this for support library as well. Try and see if it does the trick.

Atul O Holic
  • 6,692
  • 4
  • 39
  • 74
  • No, it just dismisses the home icon. But title is still clickable. – Lingviston Feb 24 '14 at 08:10
  • It did work me. However I have edited some thing. Can you try this one? – Atul O Holic Feb 24 '14 at 10:10
  • And you will have to create a new theme and applly it to your activity dynamically in onCreateView method of your fragment. Write this code - final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.yourCustomTheme); Source - http://stackoverflow.com/questions/9469174/set-theme-for-a-fragment – Atul O Holic Feb 24 '14 at 10:18
  • But I need to dynamically make it clickable or not. I can't achieve this via styles. – Lingviston Feb 24 '14 at 11:41
  • why not, apply this style in onCreateView() of 2nd Fragment and in the 1st Fragment apply a different one. – Atul O Holic Feb 24 '14 at 11:42