我正在尝试在我的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="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>
app_bar.xml
:
<?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>
</android.support.design.widget.CoordinatorLayout>
然而,当我这样做时,我的EditText
覆盖了我的工具栏。这是一张显示发生情况的图片:
我真的不明白为什么会发生这种情况,无论如何都要调整我的EditText
所以它不会覆盖工具栏?谢谢!
更新:将Arya的代码添加到我的代码后,我的图像看起来像是这样,这使得ActionBar
太高了。关于如何解决它的任何想法?
答案 0 :(得分:2)
您的布局在其当前定义中没有多大意义。我认为这里的问题是CoordinatorLayout
已被分配fitsSystemWindows=true
。这使得它从状态栏的最顶部报告bottom
。另一方面,RelativeLayout
期望状态栏底部的bottom
值。这会使EditText
与Toolbar
重叠25dp
- 状态栏的标准高度。您可以通过将android:fitsSystemWindows="true"
分配给ID为RelativeLayout
的{{1}}来确认这一点。在这种情况下,create_post
bottom
将被正确报告,而CoordinatorLayout
不会与EditText
重叠。
通常,Toolbar
设置为父级,内容(在您的情况下为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>
置于CoordinatorLayout
内的具体原因,请分享。
答案 1 :(得分:1)
<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>
答案 2 :(得分:0)
<android.support.design.widget.AppBarLayout
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">