Android 查看操作工具栏?
我正在尝试在我的scren上创建一个与Android 查看操作工具栏?,android,android-layout,android-toolbar,android-relativelayout,android-coordinatorlayout,Android,Android Layout,Android Toolbar,Android Relativelayout,Android Coordinatorlayout,我正在尝试在我的scren上创建一个与EditText关联的工具栏。下面是我正在尝试创建的xml文件的内容: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="matc
EditText
关联的工具栏。下面是我正在尝试创建的xml文件的内容:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tool="http://schemas.android.com/tools"
tool:context=".CreatePost"
android:id="@+id/create_post">
<include layout="@layout/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/create_post_toolbar"/>
<!-- Edit text for typing status. Light gray placeholder. -->
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColorHint="#d3d3d3"
android:layout_below="@id/create_post_toolbar"
android:hint="Update your friends!"
android:padding="10dp"
android:gravity="top"
android:background="@android:color/transparent"
android:inputType="textMultiLine"
android:id="@+id/type_status"/>
</RelativeLayout>
但是,当我这样做时,我的EditText
会覆盖我的工具栏。下面是一张显示发生了什么的图片:
我真的不明白为什么会发生这种情况,是否需要对齐我的EditText
,使其不覆盖工具栏?谢谢
更新:将Arya的代码添加到我的图像中后,我的图像看起来是这样的,这使得操作栏
过高。有没有办法解决这个问题
按照当前的定义,您的布局没有多大意义。我认为这里的问题是,
协调器布局
已分配fitsystemwindows=true
。这使得它可以从状态栏的顶部报告其底部。另一方面,RelativeLayout
需要状态栏底部的bottom
值。这使您的EditText
与工具栏重叠25dp
——状态栏的标准高度。您可以通过将android:fitsystemwindows=“true”
分配给id为create\u post
的RelativeLayout来确认这一点。在这种情况下,将正确报告CoordinatorLayout
的底部
,并且编辑文本
不会与工具栏
重叠
通常,CoordinatorLayout
被设置为父级,内容(在您的情况下,RelativeLayout
)作为CoordinatorLayout
的子级驻留:
<?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=".CreatePost">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_universal"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/create_post">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColorHint="#d3d3d3"
android:hint="Update your friends!"
android:padding="10dp"
android:gravity="top"
android:background="@android:color/transparent"
android:inputType="textMultiLine"
android:id="@+id/type_status"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
如果您有特定的理由将协调器布局放置在RelativeLayout
中,请进行共享。您好,操作栏现在正确显示,而不会被编辑文本隐藏,但现在操作栏太高。我已经更新了上面的帖子来展示它现在的样子。有没有办法解决这个问题?我也不想使用app:titleMarginTop=“13dp”
。谢谢这并没有解决问题。这和上面的一模一样。哇,这太神奇了。非常感谢你。它工作得很好。我感谢你的帮助!:)只有一个问题:我的大部分活动(如果不是全部的话)都有一个AppBarLayout
。在这个回答中,我看到您直接在文件中提供了AppBarLayout
,而不是将其放入另一个文件中,我可以在该文件中执行
。在我的上下文中,我不能在每个文件中都包含app_bar.xml
,并且有这样的布局,因此我必须在使用它的每个文件中声明它?另外,将协调布局
放在RelativeLayout
中是否错误?我看到了一些这样的例子:人们把它放进去了。实际上这样做的原因是什么?@user1871869不,您仍然可以使用
-但仅限于
。因此,您的设置将如下所示:
。我希望这足够清晰。但是,我确实明白你的意思,不幸的是,
将不得不放在每个布局文件中。@user1871869好吧,除了你刚才面临的问题之外,将协调布局
放在相对布局
中,文档指出了主要的用例:#1是我一直使用协调器布局的方式#这意味着把它放在另一个容器中应该是可行的。但我自己没做过。因此,这本身并没有错。也许,在另一个ViewGroup
中放置CoordinatorLayout
时,只需删除fitsystemwindows
属性。
<android.support.design.widget.AppBarLayout
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/htab_maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/tabheader"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/htab_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/htab_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
</android.support.design.widget.AppBarLayout>
<?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=".CreatePost">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_universal"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/create_post">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColorHint="#d3d3d3"
android:hint="Update your friends!"
android:padding="10dp"
android:gravity="top"
android:background="@android:color/transparent"
android:inputType="textMultiLine"
android:id="@+id/type_status"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>