简体   繁体   English

ActionBar:“向上”图标和“溢出”菜单图标未出现,但可以使用

[英]ActionBar: Up icon and Overflow menu icons not appearing, but working

The ActionBar on my app, which is a toolbar, does not show the icons for the UP button, nor the overflow menu, just a white bar. 我的应用程序上的ActionBar(是工具栏)不显示UP按钮的图标,也不显示溢出菜单,而仅显示白色条。 However, these still work- if you touch where they are supposed to be . 但是,这些仍然有效-如果您触摸它们应该位于的位置 They simply are not appearing. 它们根本没有出现。

I've compared the theme, xml, and manifests to an older app of mine which did not share the same problems, and found no differences. 我已经将主题,xml和清单与我的一个较旧的应用程序进行了比较,该应用程序没有相同的问题,也没有发现任何差异。 So I am completely lost. 所以我完全迷路了。

Styles xml 样式xml

<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" parent= "AppTheme">
        <!-- Customize your theme here. -->

        <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" />

Activity_main.xml Activity_main.xml

<android.support.design.widget.CoordinatorLayout 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/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.xu.servicequalityrater.CameraActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" >


        <TextView android:textSize="20dp" android:textColor="@color/black" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Veritas" />



    </android.support.v7.widget.Toolbar>



</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />



</android.support.design.widget.CoordinatorLayout>

Manifest excerpt 清单摘录

 <activity
            android:name=".CameraActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme_NoActionBar" />

Any advice by members who have faced similar issues is extremely welcome! 非常欢迎遇到类似问题的成员提供任何建议!

As you are using Theme.AppCompat.Light.DarkActionBar , your toolbar back icon and overflow icon showing as white color and I guess you have used colorPrimary as white . 当您使用Theme.AppCompat.Light.DarkActionBar ,工具栏的back图标和overflow图标显示为white ,我猜您已将colorPrimary用作white

Change colorPrimary to other color OR you can use Theme.AppCompat.Light , it will show back and overflow icon as black . colorPrimary更改为其他颜色,或者可以使用Theme.AppCompat.Light ,它将显示back并且overflow图标为black

Here is the fully working code 这是完整的工作代码

Style.xml: Style.xml:

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <item name="colorPrimary">@color/colorPrimary</item> <!-- WHITE -->
        <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: AndroidManifest.xml:

<activity android:name=".MainActivity"
    android:theme="@style/AppTheme.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

activity_main.xml activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
</LinearLayout>

MainActivity.java: MainActivity.java:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
}

OUTPUT: 输出:

在此处输入图片说明

Hope this will help~ 希望这会有所帮助〜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM