我需要将我的 Activity 设置为全屏,没有状态栏和操作栏
这是我在谷歌上的代码库。我添加了 NoTitleBar 和全屏
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<activity
android:name="com.examples.hello.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
问题是我的应用程序不喜欢 Theme.AppCompat。我该如何解决这个问题?
我的日志
> 04-09 11:22:35.570: E/AndroidRuntime(3931):
> java.lang.RuntimeException: Unable to start activity
> ComponentInfo{com.examples.hello/com.examples.hello.MainActivity}:
> java.lang.IllegalStateException: You need to use a Theme.AppCompat
> theme (or descendant) with this activity.
最佳答案
试试这个:
务实地:
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);
}
}
通过 Manifest 文件中的 XML:
<activity android:name=".ActivityName"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
关于android - 将 Android Activity 设置为全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22952156/