簡體   English   中英

應用程序主題(動作欄)不尊重您的空間

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

我使用的是Navigation Drawer ,但是每次我在片段中放置一些內容時,操作欄都不尊重布局。

圖片本身說明:

在此處輸入圖片說明

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>

還有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);
}

}

使用自定義工具欄會帶來一些后果。 自定義工具欄具有高度,默認情況下其他元素不尊重高度,我們必須將其設置為padding或margin。 在工具欄的高度上添加到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