我正在从这个教程中学习Android:
http://gamecodeschool.com/android-projects/,但是有一个问题。在某些游戏中,您需要在XML文件中设置全屏分辨率。我正在做正确的教程,但我的游戏崩溃时,我安装在一个设备。只是因为这个XML文件。我很生气,我试着自己学习,但是我总是有这个全屏的bug。这是代码
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
发布于 2017-09-30 08:15:05
尝尝这个
public class ActivityName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}AndroidManifest.xml文件来做。<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/><activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.AppCompat.Light.NoActionBar"/>styles.xml中根据自己的创建进行定制<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="theme_fullScreen" parent="android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>发布于 2017-09-30 06:56:33
试试这个。
清单中的way 1.set
<activity
...
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />java代码中的way 2.set
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// add this before setContentView methood ,and after super
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);
setContentView(R.layout.activity_main);
}方法3.set在清单中,并按样式设置
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="theme_fullScreen" parent="android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
</resources>在舱单上
<activity android:name=".LoginActivity"
android:theme="@style/theme_fullScreen"/>Note
android:theme的Activity。getWindow().setFlags(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);发布于 2017-09-30 08:36:45
其他答案是正确的,但我提供了一个解决方案,我正在使用,甚至在通知或任何其他焦点更改时,它仍然保持原状或回到原来的状态。
把这个放在你的活动中
这将给你最好的全屏幕活动,就像一个游戏活动。
https://stackoverflow.com/questions/46500340
复制相似问题