【问题标题】:Full screen transparent activity (no title & status bar) doesn't work.... why?全屏透明活动(无标题和状态栏)不起作用....为什么?
【发布时间】:2012-01-27 06:13:13
【问题描述】:

我正在制作自定义锁屏。

锁屏是我在屏幕关闭时启动的活动。

但是,我不能让活动既透明又全屏。

状态栏一直显示。

这是我在清单中所做的:

<activity android:name=".activities.LockScreenActivity"  android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>

我还在 activit 的 onCreate 中添加了这些附加功能:

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.lock_screen);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

但它似乎无法工作:|

为什么?

【问题讨论】:

    标签: android android-activity lockscreen


    【解决方案1】:

    从 onCreate() 中删除代码。在 Manifestfile 中使用它。

    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
    

    否则根据您的要求创建主题。

    【讨论】:

    • 不起作用我的朋友.. 这与 ?
    • 最好使用半透明和nototlebar。
    • 我不确定我是否关注你。正如我所说,我在清单中写了 android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" 你告诉我在 onCreate 中使用它: setTheme(android.R.style.Theme_Translucent_NoTitleBar_Fullscreen); .如果我错了,请纠正我,但这不是一回事吗?
    • 两者都是一样的,它对我有用,删除onCreate中的东西。仅用于设置任一清单。
    • 很奇怪。我无法让它工作。当我使用“Theme.NoTitleBar.Fullscreen”时,状态栏消失了。但是当我使用“Theme.Translucent.NoTitleBar.Fullscreen”时,状态栏仍然存在。您可以发布代码或添加对您有用的项目吗?谢谢
    【解决方案2】:

    您需要在 setContentView 之前设置标志,然后它应该可以正常工作

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    setContentView(R.layout.lock_screen);
    

    【讨论】:

      【解决方案3】:

      这里是link(在 Android 4.1 及更高版本上隐藏状态栏)。

      View decorView = getWindow().getDecorView();
      // Hide the status bar.
      int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
      decorView.setSystemUiVisibility(uiOptions);
      // Remember that you should never show the action bar if the
      // status bar is hidden, so hide that too if necessary.
      ActionBar actionBar = getActionBar();
      actionBar.hide();
      

      在 Android 4.0 及更低版本上隐藏状态栏:

      <application
          ...
          android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
          ...
      </application>
      

      @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              // If the Android version is lower than Jellybean, use this call to hide
              // the status bar.
              if (Build.VERSION.SDK_INT < 16) {
                  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                          WindowManager.LayoutParams.FLAG_FULLSCREEN);
              }
              setContentView(R.layout.activity_main);
          }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-01-25
        • 2015-07-06
        • 1970-01-01
        • 2015-04-01
        • 1970-01-01
        • 2021-02-26
        • 1970-01-01
        相关资源
        最近更新 更多