【问题标题】:how to set status bar with gradient drawable same as action bar?如何设置与操作栏相同的渐变可绘制状态栏?
【发布时间】:2018-11-24 06:32:04
【问题描述】:

我尝试了很多方法,但它与工具栏和状态栏重叠。此外,它还返回按底部导航默认值。 我在下面添加了代码-

 @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  Window w = getWindow();  w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);//allow window to extend outside of the screen.
            w.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);// override FLAG_FULLSCREEN and force the screen decorations (such as the status bar) to be shown.         w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR);            w.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);           w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        super.onCreate(savedInstanceState);

    }

【问题讨论】:

  • 您是否在使用 NoActionBarTheme 并创建自己的工具栏?还是相反?顺便说一句,用户界面看起来不错。
  • 感谢您的回复,是的,我正在使用自定义工具栏,并且我已将 drawble 渐变文件添加到工具栏背景
  • @Prachi rane 我已经发布了一个代码看看这个stackoverflow.com/a/48556397/7609347

标签: android gradient drawable statusbar


【解决方案1】:

在 setContentView 之前调用此方法。

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setStatusBarGradiant(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        Drawable background = activity.getResources().getDrawable(R.drawable.gradient_theme);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(activity.getResources().getColor(android.R.color.transparent));
        window.setNavigationBarColor(activity.getResources().getColor(android.R.color.transparent));
        window.setBackgroundDrawable(background);
    }
} 

还要确保您使用的是主题 AppTheme.NoActionBar。检查this。如果它不起作用,请检查问题的其他答案。

要隐藏底部导航栏,请使用此

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

查看this了解更多信息。

【讨论】:

  • 感谢您的回答,它可以工作,但不能删除底栏
  • 你说的是哪个底栏?
  • 灰色
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多