底部导航视图收缩

问题描述 投票:1回答:3

当我从优惠券片段更改为任何其他片段时,我已经制作了一个带有促销,商店,奖励,优惠券和帐户标签的底部导航视图的应用,底部导航视图缩小,如图所示,我尝试更改布局宽度,高度和转换协调器布局到线性布局,但它没有帮助。当我从家里切换到任何其他选项卡时,问题就出现了。

布局文件activity_main.xml

<android.support.constraint.ConstraintLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">

<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="56dp"
    android:text="@string/title_home"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="@color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:itemTextColor="@color/selector_bottom_navigation"
    app:itemIconTint="@color/selector_bottom_navigation"
    app:menu="@menu/navigation" />

Java文件MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //loading the default fragment
    loadFragment(new PromoFragment());

    //getting bottom navigation view and attaching the listener
    BottomNavigationView navigation = findViewById(R.id.navigation);
    BottomNavigationViewUtils.disableShiftMode(navigation);
    navigation.setOnNavigationItemSelectedListener(this);
}

@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
    getMenuInflater().inflate(R.menu.menu_wallet, menu);
    return super.onCreatePanelMenu(featureId, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.menu_wallet1:
            return true;
        case R.id.menu_qrcode:
            Intent intent = new Intent(this, ScannerActivity.class);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    Fragment fragment = null;

    switch (item.getItemId()) {
        case R.id.navigation_promo:
            fragment = new PromoFragment();
            break;

        case R.id.navigation_store:
            fragment = new StoreFragment();
            break;

        case R.id.navigation_reward:
            fragment = new RewardFragment();
            break;

        case R.id.navigation_coupon:
            fragment = new CouponFragment();
            break;

        case R.id.navigation_account:
            fragment = new AccountFragment();
            break;
    }

    return loadFragment(fragment);
}

private boolean loadFragment(Fragment fragment) {
    if (fragment != null) {
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.fragment_container, fragment)
                .commit();
        return true;
    }
    return false;

这是我的意思

enter image description here

我之前将SearchView添加到优惠券片段和片段存储中

android android-fragments searchview bottomnavigationview
3个回答
1
投票

事实证明,如果您在片段中使用协调器布局和viewpager,您会注意到viewpager会稍微扩展屏幕。只需禁用片段内协调器布局的滚动功能,您会发现底栏不会缩小。奇怪我知道,但它的确有效。


1
投票

我在CoordinatorLayout中添加了android:fitsSystemWindows =“false”并且它有效


1
投票

在片段xml中找到android:fitsSystemWindows="true"并删除此行或将其更改为android:fitsSystemWindows="false"。你的问题将得到解决。

© www.soinside.com 2019 - 2024. All rights reserved.