导航栏显示在通知栏下方

时间:2019-11-05 16:59:38

标签: android

我正在使用已编辑的默认导航栏项目,因此导航栏位于oon home.xml,并且编辑了主要的javascript文件:

package com.invy55.quadernoelettronico;

import ...

public class MainActivity extends AppCompatActivity {

    private AppBarConfiguration mAppBarConfiguration;

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

        SharedPreferences prefs = getSharedPreferences("UserData", MODE_PRIVATE);
        String uname = prefs.getString("username","");
        String pwd = prefs.getString("password","");
        EditText username = findViewById(R.id.username);
        username.setText(uname);
        EditText password = findViewById(R.id.password);
        password.setText(pwd);
    }

    @Override
    public boolean onSupportNavigateUp() {
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        return NavigationUI.navigateUp(navController, mAppBarConfiguration)
                || super.onSupportNavigateUp();
    }

    public void blogin(View v) {
        EditText unameet = findViewById(R.id.username);
        String username      =  unameet.getText().toString();
        EditText passw = findViewById(R.id.password);
        String password      =  passw.getText().toString();
        SharedPreferences prefs = getSharedPreferences("UserData", MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString("username", username);
        editor.putString("password", password);
        editor.apply();
        setContentView(R.layout.home);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        NavigationView navigationView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        mAppBarConfiguration = new AppBarConfiguration.Builder(
                R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow,
                R.id.nav_tools, R.id.nav_share, R.id.nav_send)
                .setDrawerLayout(drawer)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
        NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
        NavigationUI.setupWithNavController(navigationView, navController);

    }
}

一切正常,但是当我启动应用程序并到达home.xml页面时,使用了登录按钮(如您在此处的代码中所见),该栏显示了错误:

BUg

但是,如果然后我在菜单中按了主页之类的按钮(这是当前页面),它可以毫无问题地修复。

PS:当我单击菜单中的“主页”按钮时,它将运行以下脚本:

package com.invy55.quadernoelettronico.ui.home;

import ...

public class HomeFragment extends Fragment {

    private HomeViewModel homeViewModel;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        homeViewModel =
                ViewModelProviders.of(this).get(HomeViewModel.class);
        View root = inflater.inflate(R.layout.fragment_home, container, false);
        final TextView textView = root.findViewById(R.id.text_home);
        homeViewModel.getText().observe(this, new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                textView.setText(s);
            }
        });
        return root;
    }
}

编辑

我从home.xml中删除了android:fitsSystemWindows="true",它对我有用。

1 个答案:

答案 0 :(得分:0)

fitsSystemWindows首先应用深度-顺序很重要:这是第一个使用插图的视图,这会有所作为。只需插入xml中的Layout / Toolbar旁边即可。

android:fitsSystemWindows="true"