Yanshof
Yanshof

Reputation: 9926

how to change the 3 dot on the Toolbar color and change the Toolbar text on run time

I can't change the 3 dot ( Setting ) color.

And I can't find a way to change the Toolbar text on run time.

enter image description here

Upvotes: 0

Views: 777

Answers (2)

Saran Sankaran
Saran Sankaran

Reputation: 2606

You can change the colour of the icon something like this.

@Override
public boolean onCreateOptionsMenu(Menu menu) {  
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    MenuItem menuItem = menu.findItem(R.id.my_item_id);

    if (menuItem != null) {
        tintMenuIcon(this, menuItem, android.R.color.my_color);
    }

    return true;
}

public void tintMenuIcon(Context context, MenuItem item, @ColorRes int color) {  
    Drawable normalDrawable = item.getIcon();
    Drawable wrapDrawable = DrawableCompat.wrap(normalDrawable);
    DrawableCompat.setTint(wrapDrawable, context.getResources().getColor(color));

    item.setIcon(wrapDrawable);
}

And to chage the title you can do

ActionBar actionBar = getSupportActionBar();
if(actionBar != null){
    actionBar.setTitle("My Title");
}

but don't forget to set the action bar before calling getSupportActionBar().

Upvotes: 0

Anton Kazakov
Anton Kazakov

Reputation: 2774

It's called overflow button you can change it's icon using simple styles.

<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
    <item name="actionOverflowButtonStyle">@style/OverFlow</item>
</style>

<style name="OverFlow" parent="Widget.AppCompat.ActionButton.Overflow">
    <item name="android:src">@drawable/new_icon</item>
</style>

or in Java code

toolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.new_icon));

Upvotes: 1

Related Questions