2016-09-20 52 views
3

我無法按照視頻指示以全屏模式運行我的Android應用程序。當它嘗試運行時,該應用程序崩潰與錯誤。如何解決:「您需要在此活動中使用Theme.AppCompat主題(或後代)」

"You need to use a Theme.AppCompat theme (or descendant) with this activity

清單文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.djsg38.hikerswatch"> 

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity" 
     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> 

</manifest> 

樣式文件

<resources> 

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

部分MainActivity可能有用

public class MainActivity extends AppCompatActivity { 

回答

27

你的應用程序有一個程序兼容性主題

<application 
    android:theme="@style/AppTheme"> 

但是,您已改寫與未後代的程序兼容性主題的主題活動(延伸AppCompatActivity)

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

你可以定義您自己的全屏主題像這樣(請注意AppCompatparent=

<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowActionBar">false</item> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
</style> 

然後在活動上設置它。

<activity android:name=".MainActivity" 
    android:theme="@style/AppFullScreenTheme" > 

注意:有可能是一個程序兼容性的主題,就是已經滿屏幕,但如果添加了android:theme="@style/Theme.AppCompat.Light"在AndroidManifest.xml文件<application>,問題解決不立即

+0

我會試試這個,雖然它的確很像我試過的東西。對不起,我應該已經發布了一段代碼,我沒有使用「Theme.NoTitleBar ...」 –

+0

我只是想說,我不得不刪除「android:theme = @ style/AppFullScreenTheme」活動部分。有了它,它會導致應用程序因活動無法分配而中斷。 –

+0

你是什麼意思「不可轉讓」?您必須在'styles.xml'中添加'AppFullScreenTheme'風格,然後您可以在清單中使用它作爲書寫 –

-1

知道。

相關問題