0

我的应用程序(它是一个工具栏)上的ActionBar不显示UP按钮的图标,也没有显示溢出菜单,只是一个白色条。 然而,这些仍然有效 - 如果你触摸它们应该是。他们根本没有出现。ActionBar:向上图标和溢出菜单图标没有出现,但正在工作

我将主题,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中

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

清单摘录

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

由会员有什么建议谁面临类似的问题是非常欢迎!

回答

1

当您使用Theme.AppCompat.Light.DarkActionBar,您的工具栏图标backoverflow图标显示为white颜色,我想你已经使用colorPrimary作为white

变化colorPrimary到其他颜色或者你可以用Theme.AppCompat.Light,它会显示backoverflow图标为black

这里是全工作代码

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:

<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中

<?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:

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:

enter image description here

希望这将有助于〜

+0

你是正确的,我用白色作为我主颜色。我只是尝试了你的建议,没有改变:(编辑:只是改变了我的主要颜色为黑色,并且所有的图标都显示出来了,这是一个颜色问题,谢谢你,我会调整这个,直到我得到白色的工作 –

+0

我有使用相同的主题和它的工作正常 – FAT

+0

如果我的答案似乎有用,我希望你会给一个加票。:) – FAT