我已经像youtube应用程序一样,在LANDSCAPE模式下全屏查看。但是遇到了一个问题,我无法在应用程序中隐藏标题栏。我没有用夏洛克动作棒。相反,我使用自定义的标题栏。
getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN,LayoutParams.FLAG_FULLSCREEN)
getWindow().clearFlags(LayoutParams.FLAG_FULLSCREEN)
requestWindowFeature(Window.FEATURE_NO_TITLE)
这三种说法我都用过了。但它不起作用。
或者第二种方法可以添加到清单文件中,那么就不需要在活动类中添加有问题的内容
<activity
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
/>
或者你只能在横向使用这一个
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) //To fullscreen
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.your_layout_name);
}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
// no need to fullscreen
setContentView(R.layout.your_layout_name);
}
}
在onCreate()
setContentView();
之前使用这些
类似
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.your_layout_name);
}
使用这个:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
在setContentView()之前!
我用这个解决了我的问题:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
我也试图在Android 2.2上隐藏Action Bar,但这些解决方案都不起作用。一切都以崩溃告终。我检查了DDMS LOg,它告诉我使用"Theme.AppCompat"。最后我通过更改android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
行解决了问题
进入android:theme="@style/Theme.AppCompat.NoActionBar"
并工作,但界面是黑暗的。
然后我尝试了android:theme="@style/Theme.AppCompat.Light.NoActionBar"
,最终得到了我想要的。
之后,当我在开发者网站上搜索"AppCompat"时,我得到了这个。
所以我认为Android 2.2的解决方案是
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
很抱歉我的英语一如既往地不好。
您可以在menifest.xml中为全屏定义主题。
<activity
android:name=".MainActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
this.requestWindowFeature(Window.FEATURE_NO_TITLE);this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LlayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
这实际上适用于Jorge Freitas,我不能投票给他,因为我没有足够的"声誉"。。。。