简体   繁体   English

应用程序主题(动作栏)不尊重您的空间

[英]App Theme(Actionbar) is not respecting your space

I'm using a Navigation Drawer , but every time I put something in the fragment, the action bar does not respect the layout. 我使用的是Navigation Drawer ,但是每次我在片段中放置一些内容时,操作栏都不尊重布局。

The image itself explains: 图片本身说明:

在此处输入图片说明

The fragment_main : fragment_main:

<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="com.example.leonel.picollo.MainFragment">

<Button
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="MAIN"
   android:padding="8dp"
   android:textColor="#fff"
   android:background="@color/colorPrimary"
   android:textSize="28sp"
   android:id="@+id/textView"
   android:layout_centerHorizontal="true"
   android:layout_centerVertical="true"
/>

</RelativeLayout>

And the MainFragment.java : 还有MainFragment.java:

package com.example.leonel.picollo;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class MainFragment extends Fragment {


public MainFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_main, container, false);
}

} }

Using custom toolbar has some consequences. 使用自定义工具栏会带来一些后果。 Custom toolbar has height and other elements don't respect it in default, we must set them padding or margin. 自定义工具栏具有高度,默认情况下其他元素不尊重高度,我们必须将其设置为padding或margin。 Add to RelativeLayout marginTop on height of Toolbar. 在工具栏的高度上添加到RelativeLayout marginTop。

<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"
android:marginTop="?attr/actionBarSize" <!-- here is marginTop -->
tools:context="com.example.leonel.picollo.MainFragment">
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM