android将工具栏标题颜色更改为白色 [英] android change toolbar title color to white
本文介绍了android将工具栏标题颜色更改为白色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中的工具栏标题显示为灰色,而不是白色。下面是代码。请帮助我编辑了代码。我已经包括java代码和整个activity_main.xml
The toolbar title in my application displays grey color instead of white.Below is the code.Please help me!!I have edited the code.I have included java code and entire activity_main.xml
Java代码:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
activity_main.xml:
activity_main.xml:
<?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"
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg7"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#50000000"
app:theme="@style/ActionBarThemeOverlay"
app:popupTheme="@style/ActionBarPopupThemeOverlay"
/>
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/MaterialSearchView"/>
<ImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#90000000" />
<RelativeLayout
android:id="@+id/relative2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true">
<ImageView
android:id="@+id/image1"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="right|center_vertical"
android:layout_marginLeft="20dp"
android:background="@drawable/marker"></ImageView>
<fr.ganfra.materialspinner.MaterialSpinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="10dp"
app:ms_alignLabels="false"
app:ms_arrowColor="@color/arrow"
app:ms_arrowSize="8dp"
app:ms_hintColor="@color/hint"
app:ms_multiline="true"
app:ms_thickness="0.0dp"
app:popupTheme="@android:color/transparent"
/>
</RelativeLayout>
</RelativeLayout>
styles.xml:
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
colors.xml:
<
colors.xml: <
color name="colorPrimary">#8C9EFF</color>
<color name="colorPrimaryDark">#903F51B5</color>
<color name="colorAccent">#ffffff</color>
屏幕截图:
推荐答案
这是使用java更改工具栏颜色的另一种方法
this is other way to change the toolbar color using java
toolbar.setTitleTextColor(ContextCompat.getColor(getApplicationContext(), R.color.YOUR_COLOR));
如果您的最低API级别低于23,则可以执行此操作。
If your min API level is under 23, it could do the job.
一如既往,如果我错了,请更正我。
As always, If I'm wrong, please correct me.
这篇关于android将工具栏标题颜色更改为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文