有人可以告诉我为什么我的文本背景在我的工具栏中是白色的吗?

时间:2016-10-08 19:06:30

标签: android android-layout android-xml android-toolbar

以下是我的应用的图片:

screenshot

如您所见,工具栏中文本的背景设置为与工具栏背景不同的颜色,我该如何解决?

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mddri_.myeats">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <meta-data
        android:name="android.app.searchable"
        android:resource="@xml/searchable" />

    <activity android:name=".main.MainActivity">

    </activity>
    <activity android:name=".viewdatabase.ViewDatabase">
        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
    </activity>
    <activity android:name=".viewmeals.ViewMeals" />
    <activity android:name=".viewkitchen.ViewKitchen" />
    <activity
        android:name=".main._MainActivity"
        android:label="@string/title_activity___main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

主要布局:

<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.mddri_.myeats.main._MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabMode="scrollable"
    android:layout_below="@+id/my_toolbar"
    android:background="@color/colorPrimary"
    />
<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/tab_layout"/>

样式:

<resources>

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


</resources>

颜色

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#C0FF3E</color>
<color name="colorPrimaryDark">#04a314</color>
<color name="colorAccent">#8a9b8c</color>
<color name="textColor">#555555</color>
<color name="background">#fcfcfc</color>
</resources>

感谢任何帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

我从我的样式文件中删除了<item name="android:background">@color/background</item>,就像Sunil建议的那样有效。