Reputation: 3149
I am trying to change the text color of the toolbar,but at no vail. Here is my code.
styles.xml
<!-- Base application theme. -->
<style name="BasicTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="ToolbarTheme" parent="BasicTheme">
<item name="android:textColor">@color/text_color</item>
</style>
tool_lay
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:appo="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/toolbar"
android:elevation="10dp"
android:background="@color/colorPrimary"
appo:theme="@style/ToolbarTheme"
>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="testing.theo.aelfootballclub.MainActivity"
android:background="#3d827e">
<include
android:id="@+id/toolbar"
layout="@layout/tool_lay"
/>
<LinearLayout
android:padding="20dp"
android:background="#6e7398"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:orientation="vertical"
android:layout_height="wrap_content">
<EditText
android:id="@+id/user_name"
android:hint="Userame"
android:layout_width="250dp"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/user_pass"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginTop="20dp"
android:hint="Κωδικός"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_gravity="center_horizontal"
android:text="Εισοδος"
android:layout_marginTop="20dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:onClick="userLogin"/>
<Button
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:text="Εγγραφη"
android:layout_width="0dp"
android:onClick="userReg"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:textStyle="bold|italic"
android:textSize="25sp"
android:layout_gravity="center_horizontal"
android:text="Ξεχασες τον κωδικό?"
android:id="@+id/forgotPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
and finally my MainActivity.
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setToolbar();
}
private void setToolbar(){
toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
The background color of the toolbar works fine. I can change it to any color I want to.
Any ideas,
Thanks.
Upvotes: 1
Views: 7660
Reputation: 456
Just use this line for androidx.appcompat.widget.Toolbar:
app:titleTextColor="@color/yourColor"
Upvotes: 0
Reputation: 157
Add this to your themes.xml file
<style name="Theme.YourAppName" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
Upvotes: 0
Reputation: 3818
Use the xml attribute for changing text color in toolbar
app:titleTextColor="@color/colorAccent"
Upvotes: 2
Reputation: 1830
You can do like this
private void setToolbar(){
toolbar = (Toolbar)findViewById(R.id.toolbar);
toolbar.setTitleTextColor(ContextCompat.getColor(getApplicationContext(),R.color.yellow));
setSupportActionBar(toolbar);
}
Upvotes: 6
Reputation: 8149
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
// Title and subtitle
toolbar.setTitle(R.string.about_toolbar_title);
toolbar.setSubtitleTextColor(Color.WHITE);
toolbar.setTitleTextColor(Color.WHITE);
toolbar.setBackgroundColor(getResources().getColor(
R.color.themeToolbarColor));
toolbar.setNavigationIcon(R.drawable.ic_action_back);
toolbar.setNavigationOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Upvotes: 1
Reputation: 418
Zagórski's answer changes the theme for the title, while you can set just the title text color: Instead of defining android:textColor
, set android:textColorPrimary
.
Upvotes: 0
Reputation: 1448
In Your theme add this,
<item name="actionMenuTextColor">@color/actionMenuTextColor</item>
Upvotes: 0
Reputation: 20268
In your ToolbarTheme
override titleTextAppearance
style:
<style name="ToolbarTheme" parent="BasicTheme">
<item name="titleTextAppearance">@style/ToolbarTheme.Title</item>
</style>
<style name="ToolbarTheme.Title" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">{your_color}</item>
</style>
Upvotes: 2