2015-05-14 54 views
0

正如您可以从下面的图像看到我的操作栏菜单项重叠我的自定义ActionBar。这是因为我使用的主题.NoActionBar,然后在声明名为.java我自己的动作条如下:Android ActionBar与设置选项重叠

public class MenuActivity extends ActionBarActivity { 

private Toolbar toolbar; 

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

    toolbar = (Toolbar) findViewById(R.id.tool_bar); 
    setSupportActionBar(toolbar); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.menu, menu); 
    return super.onCreateOptionsMenu(menu); 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 

    int id = item.getItemId(); 

    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

工具栏:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
android:theme="@style/ThemeOverlay.AppCompat.Dark" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/ColorPrimary" 
android:elevation="4dp"> 

和布局......

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

tools:context=".MainActivity"> 

<include 
    android:id="@+id/tool_bar" 
    layout="@layout/custom_toolbar" 
    ></include> 

<TextView 
    android:layout_below="@+id/tool_bar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/hello_world" /> 

因此,您可以看到有一个.NoActionBar主题出现问题。我试过四处张望,并在我的菜单项的顶部添加填充,但无法使用。任何帮助赞赏。

problem image

回答

1

这完全是预期的行为,并遵循Material Design官方指南。

菜单出现在所有其他应用内UI元素之上。

它是由无论是Theme.Material主题,带给你(如果你是API> 21)或Theme.AppCompat如果您使用support-v7,因为它看起来。你不应该担心这一点。

如果这不是您期望从您的应用中获得的,请尝试切换到较旧的主题,例如Holo的东西。从设计的角度来看,这并不是真正的建议。

+0

干杯抱歉猜我只是更新自己aha –