How to edit the text and back arrow color on the action bar

1.2k Views Asked by At

I have updated my question to make it more understandable and provided more info.

The image below is my current GUI which is an second an activity and I'm trying to edit the text color and the arrow icon color to black.

The actionbar in the GUI is generated by editing the AndroidManifest.xml and using the java method, onNavigationItemSelected(MenuItem item), which will bring me back to the parent activity when I click on the arrow icon

Inside the AndroidManifest.xml I have define the title, "Trip" and its parent activity name.

So is there a way to change the text and icon color?

Current GUI

enter image description here

XML for the GUI

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.android.iplanner.Trip.ActivityTrip">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabAddTrip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        app:backgroundTint="@color/colorPrimary"
        android:clickable="true"
        app:srcCompat="@drawable/ic_add_black_24px" />

</RelativeLayout>

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

AndroidManifest.xml

<activity
            android:name=".Trip.ActivityTrip"
            android:label="Trip"
            android:parentActivityName=".ActivityMain" />
4

There are 4 best solutions below

0
Rounak Lahoti On

This is a function which i used for setting toolbar

 private void setupToolbar() {
        MyLogger.getInstance().writeInfo(TAG, "setupToolbar");
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationIcon(R.drawable.ic_arrow_back_24dp);//Image Icon 
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyLogger.getInstance().writeInfo(TAG, "Toolbar Clicked");
                    onBackPressed();
            }
        });
    }
0
Jarvis On
<style name="MyApp.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">       
<!-- THIS is where you can color the arrow! -->
<item name="colorControlNormal">@color/my_awesome_color</item>

Add MyApp.ActionBarTheme in your style

<style name="MyTheme" parent="Theme.AppCompat.Light">        
<item name="actionBarTheme">@style/MyApp.ActionBarTheme</item>
<item name="actionBarStyle">@style/MyApp.ActionBar</item>

<style name="MyApp.ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar">
<item name="elevation">0dp</item>      
<!-- style for actionBar title -->  
<item name="titleTextStyle">@style/ActionBarTitleText</item>
<!-- style for actionBar subtitle -->  
<item name="subtitleTextStyle">@style/ActionBarSubtitleText</item>

<!-- 
the actionBarTheme doesn't use the colorControlNormal attribute
<item name="colorControlNormal">@color/my_awesome_color</item>
 -->

0
Meikiem On

try this to change Title:

yourToolbar.setTitle("My title”);

and this to change icon:

final Drawable yourIcon = getResources().getDrawable(R.drawable.your_icon);
yourIcon.setColorFilter(Color.parseColor(color_you_want),
PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(yourIcon);
0
Khee On

thank you for your help and sorry to waste everybody time.

I have manage to change the text color and icon color to black.

My solution is below:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

By changing the AppTheme to "Theme.AppCompat.Light" and AppTheme.AppBarOverlay to "ThemeOverlay.AppCompat.Light".