相关疑难解决方法(0)

片段重叠工具栏的布局

使用以下代码替换/将我的Fragment放在DrawerLayout的FrameLayout中:

<?xml version="1.0" encoding="utf-8"?>
  <android.support.v4.widget.DrawerLayout      
  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/drawer_layout"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  tools:openDrawer="start">


<include
    layout="@layout/app_bar_base"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


<!--drawer items-->
<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_base"
    app:menu="@menu/activity_base_drawer" />

 </android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

app_bar_base.xml 包含工具栏和FAB:

<?xml version="1.0" encoding="utf-8"?>
    <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:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fitsSystemWindows="true"
     tools:context=".BaseActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:id="@+id/appBar"
    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" />

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



<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

当我运行我的应用程序时,结果如下:

在此输入图像描述

如您所见,片段的布局与工具栏重叠.如何解决这个问题?

我已经尝试将Toolbar和FrameLayout放在LinearLayout中,如下所示:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"> …
Run Code Online (Sandbox Code Playgroud)

android

10
推荐指数
4
解决办法
2万
查看次数

为什么我的溢出下拉菜单位于操作栏的顶部?

操作栏顶部的下拉列表

默认情况下它不应该在操作栏下面吗?那么我做错了什么?

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
Run Code Online (Sandbox Code Playgroud)

RES /菜单/ main.xml中

<menu 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"
tools:context="com.example.test.MainActivity" >

<item
    android:id="@+id/action_settings"
    android:orderInCategory="100"
    android:title="@string/action_settings"
    app:showAsAction="never"/>
</menu>
Run Code Online (Sandbox Code Playgroud)

java android android-actionbar

8
推荐指数
3
解决办法
6831
查看次数

锚点弹出菜单溢出按钮

我正在尝试创建一个自定义弹出菜单,我想在操作栏的溢出菜单按钮上定位(如果重要的话,我正在使用Toolbarwith setSupportActionBar()for this).我发现这可以通过setAnchorView()(从" 溢出"菜单中读取" 自定义菜单"项)来完成.

但是,我似乎无法弄清楚如何检索溢出菜单作为一个视图(我可以用来设置锚点).

此外,我尝试将此锚定到活动本身的父布局,但它显示在左上方,菜单的高度等于操作栏的高度(这不是很有用).

有谁知道如何实现这一目标?

android popupmenu android-menu android-actionbar overflow-menu

6
推荐指数
2
解决办法
4899
查看次数