How to Get a Custom Icon in a Back Button

Use UINavigationBar appearance back icon for custom button?

UINavigationBar.appearance().backIndicatorImage is an optional value, therefore you won't be able to get the system default chevron from this. Rather, the system will use the image provided here if not null, otherwise revert to the system default.

If targeting iOS 13+, you can make use of Apple's SF Symbols, in particular the back button icon is referred to as chevron.left. To use this, call UIImage(systemName: "chevron.left"). For earlier versions of iOS, you'll have to use an image set asset. You could target all versions of iOS using if #available(iOS 13.0, *) { ... } else { ... }, where you display the system image if on iOS 13+ for improved UI appearance.

func addBackButton() {
let backButton = UIButton(type: .custom)
if #available(iOS 13.0, *) {
backButton.setImage(UIImage(systemName: "chevron.left"), for: .normal)
}
else {
backButton.setImage(UIImage(named: "backChevon"), for: .normal)
}
backButton.imageView?.contentMode = .scaleAspectFit
backButton.setTitle("Back", for: .normal)
backButton.setTitleColor(backButton.tintColor, for: .normal)

self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
}

How to change toolbar back button icon in android material components

If you are using a Toolbar to change the icon just use:

Toolbar toolbar = findViewById(R.id.xxx);
toolbar.setNavigationIcon(R.drawable.xxxx4);
setSupportActionBar(toolbar);

If you are using the ActionBar you can use:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.xxx);

You can also change it overriding in your app theme the homeAsUpIndicator attribute:

  <style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="homeAsUpIndicator">@drawable/...</item>
</style>

If you are using the Navigation Components, currently there isn't a way to customize the HomeAsUpIndicator icon, and it is an expected behavior with the Up button displayed when you are on a non-root destination.

There is a workaround adding an addOnDestinationChangedListener after your setup method and checking the destination.

Something like:

navController.addOnDestinationChangedListener(
new NavController.OnDestinationChangedListener() {
@Override
public void onDestinationChanged(@NonNull NavController controller, @NonNull NavDestination destination, @Nullable Bundle arguments) {
if (destination.getId() == R.id.nav_xxx) {
//With ActionBar
//getSupportActionBar().setHomeAsUpIndicator(R.drawable.xxxx);

//With a Toolbar
toolbar.setNavigationIcon(R.drawable.xxxx);
}
}
});

Sample Image

How to use an icon instead of the original back button in React Navigation?

Try this

const screenOptions = {
headerBackImage: () => (
<FontAwesomeIcon icon={faArrowAltCircleLeft} color="#fff" size={24} />
),
};

here is slack demo

Navigation bar back button custom icon?

What I ended up doing was creating a popup window over the soft input and making the soft input "arrow down" button do what I wanted on that pop up window.
To control what the soft input "arrow down" button does I had to create a class that extends EditText and override:

public boolean onKeyPreIme(int keyCode, KeyEvent event)



Related Topics



Leave a reply



Submit