Reputation: 1057
I am trying to center a logo in the MainActivity ActionBar but when I add this
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.thelogo);
getSupportActionBar().setDisplayUseLogoEnabled(true);
Is there no way to center it without having to change my RelativeLayout to a LinearLayout?
Upvotes: 2
Views: 158
Reputation: 3128
Since you can't access the view you can't center it unless there's a function for that which I don't think there is that's why I always make my own toolbars use this:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/navigation_background"
android:layout_gravity="center"/>
</androidx.appcompat.widget.Toolbar>
in your code use now:
...
setSupportActionBar(toolbar);
Make sure you get rid of the default actionbar by changing style to:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Upvotes: 2