Java 我的工具栏太高了,因此看起来很难看,下面的屏幕被裁剪了,我如何修复它?
这是我的工具栏screen.xml:Java 我的工具栏太高了,因此看起来很难看,下面的屏幕被裁剪了,我如何修复它?,java,android,Java,Android,这是我的工具栏screen.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="match_parent" androi
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Include your Toolbar -->
<include
android:id="@+id/mytoolbar"
layout="@layout/toolbar" />
</LinearLayout>
<FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<!-- Embed your fragment in a Layout View-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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"
/>
</FrameLayout>
</LinearLayout>
无效出票人:
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:fitsystemwindows=“true”,但我仍然没有帮助“活动”仅在第一次重新启动时才被删除,一切正常。我得出的结论是,这可能是由于firebase,但如何解决这个问题,并最终解决这个问题,我不能
Toolbar.xml
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
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:fitsystemwindows=“true”
设置为基本线性布局
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
更新-最终有效的答案是使用协调布局
作为基本布局
另一点——对于任何未来关注这一点的人来说,其他可能的考虑是
- 使用
true
- 将其值设置为false而不是true。这不符合逻辑,但我看到人们有时会说这是可行的
- 确保您的
工具栏中有
android:minHeight=“?attr/actionBarSize”
- 可能值得将容器工具栏
完全替换为LinearLayout
,并将toolbar
设置为truefitsystemwindows
- 使用
或坐标布局
基本布局。它们应该以不同于其他“基本”布局的方式处理抽屉布局
fitsSystemWindows
- 考虑过多的建议方式
- 如果所有这些都失败了,那么您可以覆盖
,以获得所需的布局fitSystemWindows(Rect insets)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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">
<include
android:id="@+id/mytoolbar"
layout="@layout/toolbar" />
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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"
/>
</LinearLayout>
分享你的工具栏.xml
@KrishnaSharma抱歉,我忘了现在我添加了@dimen/materialize\u工具栏
分享这一点。你应该使用android:layout\u height=“?attr/actionBarSize”
@KrishnaSharma 56dp尝试在主题中使用true
将其设置为false。我知道这不符合逻辑,但我看到人们有时会说这是可行的。另外,确保您的工具栏中有android:minHeight=“?attr/actionBarSize”
。尝试建议的多种方法。没问题,您找到解决方案了吗?(P.S-如果有帮助,请投票,干杯)不幸的是,这对我也没有帮助
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
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" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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">
<include
android:id="@+id/mytoolbar"
layout="@layout/toolbar" />
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
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"
/>
</LinearLayout>