0

I have an action bar with a title. Another string is added dynamically to the action bar. I have tried using OnSizeChanged and addOnLayoutListener to resize the action bar title according to the length of the string added latter.The action bar title is resized properly most of the times.

The issue is whenever a shorter string is dynamically added after a longer string, the size of the title is not increased. The width of the title text view remains when a shorter string replaces longer string.

DhivyaA
  • 1
  • 4

1 Answers1

0

Create a new LayoutParams object and assign it to your textView :

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1f);
textview.setLayoutParams(params );

The last parameter of the LayoutParams constructor is the weight and allows you to fill the available space with the TextView.