gpt4 book ai didi

java - Android:屏幕顶部带有标题栏间距的空白区域

转载 作者:太空宇宙 更新时间:2023-11-04 11:49:02 25 4
gpt4 key购买 nike

我遇到了一个令人恼火的错误,该错误将我的所有布局移动标题栏的间距,而标题栏却不在那里。在模拟器“Profile: Nexus 5x”中运行时有这个空间,但在我的 Oneplus 3 上看起来很正常。

我尝试通过将其视为标题栏来删除它,但我怀疑它可能是其他东西。

就像我所有布局中的某种通用填充一样。我对此很困惑。

编辑xml时在“设计”窗口中也可以看到。

编辑编辑编辑===========================================编辑编辑编辑

我发现使用 roughhike BottomBar 库并尝试显示超过 3 个图标时,由于某种原因会在屏幕顶部出现额外的空间。使用 native 设计库“BottomNavigationView”后,我没有遇到任何问题。

编辑编辑编辑===========================================编辑编辑编辑

知道什么可以作为倾斜栏的间距,但不是标题栏吗?

enter image description here

Android list .xml:

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="false">
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">

Style.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>


</style>

<style name="AppTheme.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>

</style>

Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout 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/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent">


<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true" />

</FrameLayout>

content_main:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.razze.roomee.MainActivity"
tools:showIn="@layout/app_bar_main">

</RelativeLayout>

MainActivity.java:

package com.example.razze.roomee;


public class MainActivity extends AppCompatActivity {


private static Context mContext;
private static Point windowsSize;
private FragmentManager fragmentManager;
BottomBar bottomBar;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //before
setContentView(R.layout.activity_main);

// HomeActivity uses these
mContext = getApplicationContext();
windowsSize = Utility.getDisplaySize(getWindowManager());

// Declares bottomBar and it's items
bottomBar = (BottomBar) findViewById(R.id.bottomBar);
bottomBar = BottomBar.attach(this, savedInstanceState);
bottomBar.setItems(R.menu.bottombar_menu);
bottomBar.setDefaultTabPosition(2);

// BottomBar OnClickListener
bottomBar.setOnMenuTabClickListener(new OnMenuTabClickListener() {


@Override
public void onMenuTabSelected(@IdRes int menuItemId) {

fragmentManager = getFragmentManager();

System.out.println("Menu selected: " + menuItemId);

switch (menuItemId){

case R.id.preferences:

fragmentManager.beginTransaction()
.replace(R.id.content_main,
new PreferencesActivity())
.commit();
break;

case R.id.matches:

fragmentManager.beginTransaction()
.replace(R.id.content_main,
new MatchesActivity())
.commit();
break;

case R.id.settings:

fragmentManager.beginTransaction()
.replace(R.id.content_main,
new SettingsActivity())
.commit();
break;

case R.id.home:

fragmentManager.beginTransaction()
.replace(R.id.content_main,
new HomeActivity())
.commit();
break;

case R.id.message:

fragmentManager.beginTransaction()
.replace(R.id.content_main,
new MessageActivity())
.commit();
break;
}

}

// When an icon in BottomBar that is selected, gets selected.
@Override
public void onMenuTabReSelected(@IdRes int menuItemId) { }

});

// Colors the bottombar (DOESNT WORK FOR SOME REASON
//bottomBar.mapColorForTab(0, "#FF9800");
//bottomBar.mapColorForTab(1, "#FF5252");
//bottomBar.mapColorForTab(2, "#7B1FA2");
//bottomBar.mapColorForTab(3, "#FFF352");
//bottomBar.mapColorForTab(4, "#455FA2");


}

// HomeActivity uses these
public static Context getMainContext(){ return mContext; }

public static Point getWindowSize(){ return windowsSize; }



}

提前感谢您的帮助,我们将不胜感激。

最佳答案

修改content_main:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.razze.roomee.MainActivity"
tools:showIn="@layout/app_bar_main">

</RelativeLayout>

关于java - Android:屏幕顶部带有标题栏间距的空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42039933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com