Changing the back button

Asked

Viewed 255 times

1

I’m trying to change this back boot. inserir a descrição da imagem aqui

Here on the forum I found this code

<item name="android:homeAsUpIndicator">@drawable/back</item> <!-- Icone de voltar -->

But it stayed that way:

inserir a descrição da imagem aqui

The icone took all the Toolbar and hid the title.

By code logic, this image that’s in the drawable would appear on every screen with this function. Is there any way to determine a size per code in this image? (I made the arrow image in reduced size but lost quality) It is possible to place a drawable for each screen?

1 answer

1


Placing the item android:homeAsUpIndicator in the application’s default theme will make all activities that use this theme (possibly "Apptheme") use it.

"You can determine a size by code in this image?"

The Android design guide has metrics set in that respect, I don’t think it’s possible. More references.

"I made the image of the arrow in reduced size, but lost the quality"

I recommend using the Android Asset Studio, a great online tool that can generate the images in the correct dimensions.

"It is possible to place a drawable for each screen?"

Yes, instead of defining the drawable in the theme, use the method setHomeAsUpIndicator() in each activity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.icone_toolbar); // <--
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    [...]
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.