我遇到了一个令人烦恼的错误,它通过标题栏的间距移动我的所有布局,而标题栏没有。它在模拟器“Profile:Nexus 5x”中运行时有这个空间,但在我的Oneplus 3上看起来很正常。
我已经尝试通过将其视为标题栏来删除它,但我怀疑它可能是其他东西。
就像我所有布局中的som类型的通用填充一样。我对此很难过。
在编辑xml时,也可以在“设计”窗口中看到它。
编辑编辑编辑=======================================编辑编辑编辑
我发现使用roughhike bottomBar库并尝试显示超过3个图标,出于某种原因提示屏幕顶部的额外空间。在使用原生设计库“BottomNavigationView”后,我没有遇到任何问题。
编辑编辑编辑=======================================编辑编辑编辑
知道什么可以作为tiltebar的间距,但不是标题栏?
Android manifest.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; }
}
在此先感谢您的帮助,我们将非常感激。
答案 0 :(得分:0)
使activity
全屏你可以使用:
方法1
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
</activity>
res / values / styles.xml中的;
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
方法2:使用requestWindowFeature
函数
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
同时从顶部或底部删除不必要的填充
答案 1 :(得分:0)
修改 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>
答案 2 :(得分:0)
如上所述尝试删除您的操作栏也尝试删除内容主页
中的填充顶部 android:paddingTop="@dimen/activity_vertical_margin"