我的工具栏太高了,因此看起来很丑,下面的屏幕也被裁剪了,我该如何修复它?
我的工具栏太高了,因此看起来很丑,下面的屏幕也被裁剪了,我该如何修复它?
这是我的toolbar screen.xml:
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> android:id="@+id/container_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> android:id="@+id/mytoolbar" layout="@layout/toolbar" /> android:id="@+id/container_body" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1"> xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.Activities.MenuActivity" />
它在你的手机上的显示效果:
你可以看到工具栏太高了。
清单文件:
android:name="com.example.Activities.MenuActivity" android:label="@string/title_activity_test" tools:ignore="InnerclassSeparator" /> 样式文件: MenuActivity类: setContentView(R.layout.activity_menu); Toolbar toolbar = findViewById(R.id.mytoolbar); setSupportActionBar(toolbar); Drawer(toolbar,MenuActivity.this,MenuActivity.this); if (getSupportActionBar() != null) { getSupportActionBar().setTitle("Аппараты"); } 抽屉函数: public void Drawer(Toolbar toolbar, Context context, android.app.Activity activity){ DatabaseReference rootRef2 = FirebaseDatabase.getInstance().getReference(); DatabaseReference uidRef2 = rootRef2.child("users").child(getUid()); ValueEventListener valueEventListener2 = new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { String email = dataSnapshot.child("account").getValue(String.class); String Avatar = dataSnapshot.child("Avatar").getValue(String.class); Long coinsAmount = dataSnapshot.child("coinsAmount").getValue(Long.class); String coinsView = "Баланс: " + coinsAmount; if (Avatar.equals("1")) { avatar = (R.drawable.a1); } if (Avatar.equals("2")) { avatar = (R.drawable.a2); } IProfile profile = new ProfileDrawerItem() .withName(email) .withEmail(coinsView) .withIcon(avatar); AccountHeader headerResult = new AccountHeaderBuilder() .withActivity(activity) .withHeaderBackground(R.drawable.account_header_background) .addProfiles( profile ) .build(); result = new DrawerBuilder() .withActivity(activity) .withToolbar(toolbar) .withAccountHeader(headerResult) .addDrawerItems( new PrimaryDrawerItem() .withName("Устройства") .withIcon(R.drawable.device) .withIdentifier(1) ) .addDrawerItems( new PrimaryDrawerItem() .withName("Сканер") .withIcon(R.drawable.scaner) .withIdentifier(2) ) .addDrawerItems( new PrimaryDrawerItem() .withName("Магазины") .withIcon(R.drawable.shop) .withIdentifier(3) ) .addDrawerItems( new PrimaryDrawerItem() .withName("Купоны") .withIcon(R.drawable.coupons) .withIdentifier(4) ) .addDrawerItems( new PrimaryDrawerItem() .withName("Архив Купонов") .withIcon(R.drawable.oldcoupons) .withIdentifier(5) ) .withOnDrawerItemClickListener((view, i, iDrawerItem) -> { if(iDrawerItem.getIdentifier() == 1 && !Activity.equals("Menu")){ Intent intent = new Intent(context,MenuActivity.class); startActivity(intent); } else if(iDrawerItem.getIdentifier() == 2 && !Activity.equals("Scaner")){ Intent intent = new Intent(context,DecoderActivity.class); startActivity(intent); } else if(iDrawerItem.getIdentifier() == 3 && !Activity.equals("Shop")){ Intent intent = new Intent(context,ShopActivity.class); startActivity(intent); } else if(iDrawerItem.getIdentifier() == 4 && !Activity.equals("oldCoupons")){ Intent intent = new Intent(context,oldCouponsActivity.class); startActivity(intent); } return false; }) .build(); Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(false); Objects.requireNonNull(result.getActionBarDrawerToggle()).setDrawerIndicatorEnabled(true); } @Override public void onCancelled(@NonNull DatabaseError databaseError) { } }; uidRef2.addValueEventListener(valueEventListener2); } 如何修复它以及我们如何做到?我长时间尝试修复它,我使用了android:fitsSystemWindows="true",但仍然没有帮助,活动只在第一次被切割,如果重新启动活动则一切正常。我得出结论,这可能与Firebase有关,但我无法解决这个问题和最终修复它。 Toolbar.xml: xmlns:iosched="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar_actionbar" android:layout_width="match_parent" android:layout_height="@dimen/materialize_toolbar" android:background="@color/grey_500" android:minHeight="?attr/actionBarSize" android:theme="?attr/actionBarTheme" />
问题原因:工具栏过高导致屏幕下方被裁剪。
解决方法:尝试在基本线性布局中设置android:fitsSystemWindows="true"
。如果这个方法不起作用,可以尝试以下其他方法:
- 在主题中设置<item name="android:fitsSystemWindows">true</item>
- 将android:fitsSystemWindows
的值设置为false
- 确保在Toolbar
中有android:minHeight="?attr/actionBarSize"
- 考虑使用CoordinatorLayout
或DrawerLayout
作为基本布局
- 参考官方文档中的方法覆盖fitSystemWindows(Rect insets)
- 查看这个链接了解如何覆盖fitSystemWindows(Rect insets)
- 尝试完全替换container_toolbar
的LinearLayout
为Toolbar
并将fitsSystemWindows
设置为true
- 尝试使用CoordinatorLayout
或DrawerLayout
作为基本布局
如果以上方法都不起作用,抱歉我无法提供更多解决办法。
最后,问题得到解决,并且更新了答案。如果有帮助,请点赞并将答案标记为正确。