2014-10-29 5 views
13

이것은 내 첫 번째 스택 오버 플로우 문제입니다. 내가 충분히 추가하지 않으면 나에게 벌거 벗은 채로 또는 너무 자세하게 추가한다.Android Overflow 메뉴가 작업 표시 줄/툴바 위에 위치합니까?

오버플로 메뉴를 내 앱의 상단 표시 줄 아래에 표시하려고합니다. Holo 테마를 사용했을 때이 작업은 훌륭하게 수행되었지만 appcompat v7 라이브러리를 사용하여 재질 디자인을 사용하도록 내 앱을 설정하려고합니다.

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <!-- the theme applied to the application or activity --> 
    <style name="CustomActionBarTheme" 
      parent="Theme.AppCompat.Light.DarkActionBar"> 
     <item name="colorPrimary">@color/ucla_blue</item> 
     <item name="colorAccent">@color/caldroid_white</item> 
     <item name="android:actionMenuTextColor">@color/caldroid_black</item> 
     <item name="android:windowNoTitle">true</item> 
     <item name="windowActionBar">false</item> 
    </style> 
</resources> 

을 그리고이 제대로이 레이아웃 내 도구 모음에 소재 디자인 테마를 적용 않습니다 :

그래서 내 주제는 지금 APPCOMPAT에서 확장

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/linearlayout_root_main" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"> 
    <!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. --> 
    <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/drawer_layout" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     tools:context="com.ucla.ieee.app.MainActivity"> 

     <LinearLayout 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      android:orientation="vertical"> 

      <android.support.v7.widget.Toolbar 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:background="?attr/colorPrimary" 
       android:id="@+id/toolbar" 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:minHeight="?attr/actionBarSize" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 
      <!-- As the main content view, the view below consumes the entire 
      space available using match_parent in both dimensions. --> 
      <FrameLayout 
       android:id="@+id/container" 
       android:layout_height="match_parent" 
       android:layout_width="match_parent"/> 
     </LinearLayout> 


     <!-- The navigation drawer --> 
     <fragment 
      android:id="@+id/navigation_drawer" 
      android:layout_gravity="start" 
      android:layout_height="match_parent" 
      android:layout_marginTop="?attr/actionBarSize" 
      android:layout_width="@dimen/navigation_drawer_width" 
      android:name="navigation.NavigationDrawerFragment" 
      tools:layout="@layout/fragment_navigation_drawer"/> 

    </android.support.v4.widget.DrawerLayout> 
</LinearLayout> 

그러나 어떤 이유로, 메뉴 I onCreateOptionsMenu에서 inflate하면 ​​잘못된 위치에 나타납니다. 분명히 이미지를 게시 할 수 없지만 기본적으로 오버플로 메뉴는 툴바 바로 아래에 표시되는 대신 툴바를 덮습니다. 이것은 정상적인 ActionBar에서 먼저 "Theme.AppCompat"을 사용하고 툴바에서도 사용하기 시작했습니다.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
      switch (selected) { 
       case FRONT_PAGE: 
        toolbar.inflateMenu(R.menu.main_settings); 
        return false; 
       case ANNOUNCEMENTS: 
        toolbar.inflateMenu(R.menu.refresh_settings); 
        return false; 
       case MEMBERSHIP: 
        toolbar.inflateMenu(R.menu.edit_member); 
        return false; 
       case CALENDAR: 
        toolbar.inflateMenu(R.menu.refresh_settings); 
        return false; 
       case POINTS_REWARDS: 
        toolbar.inflateMenu(R.menu.main_settings); 
        return false; 
       case HELP: 
        toolbar.inflateMenu(R.menu.main_settings); 
        return false; 
       default: 
        toolbar.inflateMenu(R.menu.main_settings); 
      } 

이 문제가 발생한 사람을 찾을 수 없습니다. 다른 사람이이 문제를 해결할 수 있기를 바랍니다. 감사!

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    tools:context="com.ucla_ieee.app.MainActivity"> 
    <item android:id="@+id/action_refresh" 
      android:title="@string/action_refresh" 
      app:showAsAction="never" /> 
</menu> 

답변

19

Material Design specifications 당 (메뉴 섹션을 참조하십시오) :

메뉴는 항상 응용 프로그램 표시 줄을 겹쳐 종이의 임시 시트는 여기

내 메뉴 중 하나의 예 앱 표시 줄의 확장 기능으로 작동하는 것이 아니라 Menu overlap app bar

그래서 당신이보고있는 것은 메뉴에 대한 정확한 자료 디자인입니다.

+1

고맙지 만 나는 이미 내 주요 활동에서 이것을 해왔다. 메뉴가 작동하지 않는다고 잘못 생각한 것이 아닙니다. http://i.imgur.com/0ybW1A9.png – Tania

+0

스크린 샷에 대한 답변이 업데이트되었습니다. 귀하가보고있는 것은 재료 디자인 메뉴입니다. – ianhanniballake

+0

오 이런, 내가 구현 한 애플 리케이션을 생각해 재료 디자인은 나에게 잘못된 생각을 주었다. 감사!! – Tania

0

오버 플로우 메뉴 매니페스트 파일을 안드로이드와 드롭 다운 메뉴가 존재하는 활동을 검색으로 이동 액션 바

android:theme="@android:style/Theme.Holo.Light" 
0

몇 가지 간단한 단계 아래에 오는 것보다, 내 것이 지금 제어를 누르고 당신이 당신의 테마 Y 일단 작성되는 경우 파일 스타일로 이동합니다

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

테마 이름을 클릭 오신 것을 환영합니다 활동 입니다 OU ... 당신이

<style name="AppTheme.NoActionBar"> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 
</style> 

이제 완료가

<item name="overlapAnchor">false</item> 
<item name="android:dropDownVerticalOffset">5.0dp</item> 

을이 두 항목을 붙여, 거기에 갈

P.S : 불행히도 여기에서 스크린 샷을 공유 할 수 없기 때문에 이미지 추가시 약간의 오류가있는 것처럼 보입니다. 하지만 당신은이 링크에서 볼 수 있습니다 Image File

관련 문제