2014-04-09 60 views
1

我需要將我的活動設置爲全屏無狀態欄和操作欄將Android活動設置爲全屏

這裏是我的代碼基於我有谷歌。我加入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. 
+0

剛剛從項目屬性中刪除庫。刪除MainActivity中與碎片有關的所有代碼。將佈局從fragment.xml移至activity_main.xml。 –

+0

發佈您的崩潰日誌。你的活動是否擴展了ActionBarActivity? – Libin

+0

哦..是的。我應該改變它嗎? – user3487657

回答

1

試試這個:

求真務實

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); 
    } 
    } 

通過XML清單文件:

<activity android:name=".ActivityName" 
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"> 
</activity> 
+0

仍在碾壓。相同的theme.appcompat錯誤 – user3487657

+0

從清單文件'android:theme =「@ android:style/Theme.NoTitleBar.Fullscreen」'中刪除此項,並使用Pragmatically aproach來做到這一點:或者您可以按照此鏈接http:// stackoverflow。 com/questions/17870881/cant-find-theme-appcompat-light-for-new-android-actionbar -support –

+0

我錯了。它擴大了行動支持 – user3487657

0
@Override 
protected 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.yourlayoutname); 
} 

把這個代碼在你onCreate方法在MainActivity你面前的setContentView。