2016-02-11 92 views
1

我升級我從SDK 22 android應用到SDK 23的Android NavigationView顏色奇怪的行爲

我只是改變了庫版本較新的一個,我的NavigationView改變。當選擇項目時出現兩個方塊,我不知道如何去除它們。

enter image description here

這裏是如何看起來像之前升級

enter image description here

這裏是我的activity.xml

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout" 
    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="match_parent"> 
    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      app:layout_scrollFlags="scroll|enterAlways" /> 

     <Button 
      android:visibility="@integer/test_button_visibility"/> 

     <android.support.v4.widget.SwipeRefreshLayout 
      android:layout_height="match_parent"> 

      <!-- A RecyclerView with some commonly used attributes --> 
      <android.support.v7.widget.RecyclerView 
       android:scrollbars="vertical"/> 
     </android.support.v4.widget.SwipeRefreshLayout> 
    </android.support.design.widget.AppBarLayout> 

    <!-- The main content view --> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:tools="http://schemas.android.com/tools" 

        tools:context=".MainActivity"> 
     <TextView 
      android:id="@+id/informationTextView" 
      android:visibility="gone"/> 
    </LinearLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:theme="@style/NavigationDrawerTheme" 
     app:menu="@menu/navigation_drawer_menu_items" 
     app:itemTextColor="@color/text_color"/> 
</android.support.v4.widget.DrawerLayout> 

我怎樣可以刪除它們的一部分嗎?

UPDATE

這裏是我的主題

<style name="NavigationDrawerTheme" parent="Widget.Design.NavigationView"> 
    <item name="android:textSize">14sp</item> 
    <item name="android:background">@color/white_text</item> 
</style> 
+0

您是否嘗試過使用'layout_width =「wrap_content」'?爲navigationview? – Mohsen

+0

@ LinX64現在試了一下,沒有幫助 – c0rp

回答

1

得到it.Check此鏈接:http://developer.android.com/reference/android/support/design/widget/AppBarLayout.html

這種看法在很大程度上取決於被用作直接子內的 CoordinatorLayout。如果在不同的 ViewGroup,內使用AppBarLayout,則其大多數功能都不起作用。

所以,只要添加AppBarLayoutCoordinatorLayout,然後它應該工作。

記住,不要忘了補充:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

在你的內容,看看這個例子還有:http://github.com/chrisbanes/cheesesquare

然後,你準備好了。

編輯︰我看到它的工作,刪除風格,刪除它,然後它應該工作。

<android.support.design.widget.NavigationView 
     android:id="@+id/left_drawer" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:divider="@android:color/transparent" 
     android:theme="@style/NavigationDrawerTheme" 
     app:itemTextColor="#b30707" 
     app:menu="@menu/drawer" /> 
+0

感謝您的回答。我將AppBar放到了CoordinatorLayout中,但它沒有幫助。這是我的最終activity.xml https://gist.github.com/c0rp-aubakirov/1f08f6b31dd0c728b5d1 – c0rp

+0

看看這個:http://paste.ofcode.org/pswcwAkwNzNvEhzFju8wcf現在一切似乎都很好。 – Mohsen

+0

不幸的是,它並沒有幫助,正方形仍然存在 – c0rp

1

你有一個自定義NavigationDrawerTheme?如果是這樣,你能提供嗎?默認情況下,「在選擇列表項目後,該項目會改變顏色以匹配應用的主要顏色(或#000000 100%)以指示選擇」(來自http://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-content

看起來像是深灰色方塊的列表項目被選中,但由於某種原因,整個項目中並未顯示高亮顯示。

+0

我更新題目 – c0rp

+0

問題是我的自定義主題 – c0rp