7

I would like to have a bigger action bar. So I change the action bar size in the style, and now I am looking for changing the icon size and put the text bigger also.

Here is my style :

<!-- Application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:textSize">22sp</item>
    <item name="android:actionBarSize">100dp</item>
    <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
    <item name="android:actionButtonStyle">@style/MyActionButtonStyle</item>
</style>

<style name="MyActionButtonStyle" parent="android:style/Widget.ActionButton">
    <item name="android:layout_width">fill_parent</item> 
</style>

<style name="MyActionBarTabText" parent="android:style/Widget.Holo.ActionBar.TabText">
    <item name="android:textColor">@color/white</item>
    <item name="android:textSize">25dp</item>
</style>

And my menu for the actionBar (menu.xml) :

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/app_setting"
        android:title="@string/app_setting"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:icon="@drawable/ic_setting"
        android:showAsAction="ifRoom" />
</menu>

And In the main class :

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);
    return true;
}

The result I have and would like Also, I tried several questions, but I was not able to make it work.

I want to change actionbar icon size

How to change actionBar icon size?

Community
  • 1
  • 1
JavaJade
  • 199
  • 4
  • 13

2 Answers2

0

While importing the icon from Vector Asset, setting the size depending on your requirement will do the job.

0

The best solution is to implement Toolbar in your layout and put TextView and define attributes on it. Here is my solution.

  • activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        tools:ignore="MissingConstraints">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:theme="@style/Theme.MyTest"
            app:popupTheme="@style/Theme.MyTest">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
                    android:textColor="@color/white"
                    android:textSize="@dimen/title_size" />
            </LinearLayout>

        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        android:layout_marginTop="?attr/actionBarSize"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation" />

</androidx.constraintlayout.widget.ConstraintLayout>

Here is styles which used in Toolbar attribute.

  • values\style.xml
...
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
...

With this way, you will have chance to change the Title color and size as you want.

ShineStar
  • 3
  • 4