1. NavigationView的menu设置了icon颜色,但页面没有改变
//在Activity中添加代码
nv.setItemIconTintList(null);
2. toolbar的三个横线颜色变白
//在 toolbar 的xml文件中添加代码
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
3. TabLayout选择后toolbar标题进行改变
//在activity中给tablayout设置选择监听
tab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
toobar.setTitle(tab.getText());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
4. 如果使用androidX webView会崩溃
//在gradle添加依赖
configurations.all {
resolationStrategy.force 'androidx.appcompat:appcompat:1.1.0-beta01'
}
6. fragment的选项菜单不显示
//在fragment的onCreate()中添加
setHasOptionsMenu(true);
startActivity(new Intent(Settings.ACTION_SETTINGS));
Intent localIntent = new Intent();
localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= 9) {
localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
localIntent.setData(Uri.fromParts("package", getPackageName(), null));
} else if (Build.VERSION.SDK_INT <= 8) {
localIntent.setAction(Intent.ACTION_VIEW);
localIntent.setClassName("com.android.settings", "com.android.setting.InstalledAppDetails");
localIntent.putExtra("com.android.settings.ApplicationPkgName", getPackageName());
}
startActivity(localIntent);
8. 点击toolbar退出应用
toolbar.setTitle("");
//当前activity支持toolbar
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
//重写 onOptionsItemSelected 方法
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId()==android.R.id.home){
finish();
}
return super.onOptionsItemSelected(item);
}