1. 程式人生 > >Android問題集錦之二十八:You need to use a Theme.AppCompat theme (or descendant) with this activity.

Android問題集錦之二十八:You need to use a Theme.AppCompat theme (or descendant) with this activity.

錯誤描述為:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

起因:
我想在Manifest中設定我的activity全屏,程式碼如下:
        <activity
            android:name=".MainActivity"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:label="@string/app_name" >

原因:
從錯誤提示中提到Theme.AppCompat theme,這是因為我們的activity一定是繼承了相容包中的類,
比如我這裡就無意中繼承了ActionBarActivity,它來自android.support.v7.app.ActionBarActivity。
所以就要使用與其配合的AppCompat的theme才行。

解決:
1.根據提示來使用AppCompat的theme,如下:
        <activity
            android:name=".MainActivity"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
            android:label="@string/app_name" >
不過我要設定全屏,但我並沒有找到,所以雖然錯誤不見了,但並沒有達到我的預期。

2.如果不是那麼強烈需要繼承自ActionBarActivity,就直接繼承Activity吧。問題自然搞定!

相關推薦

Android問題集錦You need to use a Theme.AppCompat theme (or descendant) with this activity.

錯誤描述為:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.起因:我想在Manifest中設定我的activ

我的Android進階旅------>解決錯誤You need to use a Theme.AppCompat theme (or descendant) with this activity.

#1、錯誤描述 今天,想實現Activity不顯示標題欄的效果,在專案的AndroidManifest.xml檔案,對相應的Activity新增屬性 android:theme="@android:style/Theme.NoTitleBar" 具體程式

Android實戰技巧啟動另一個App/apk中的Activity

Android提供了在一個App中啟動另一個App中的Activity的能力,這使我們的程式很容易就可以呼叫其他程式的功能,從而就豐富了我們App的功能。比如在微信中傳送一個位置資訊,對方可以點選這個位置資訊啟動騰訊地圖並導航。這個場景在現實中作用很大,尤其是朋

Java並發編程系列CompletionService

xtend cts edate strong ext [] com 喚醒 render CompletionService簡介 CompletionService與ExecutorService類似都可以用來執行線程池的任務,ExecutorService繼承了Execut

cas入門services管理控制檯

什麼是cas services管理控制檯? 想想一種情況,當你搭建好了一臺cas伺服器,大家知道了cas的訪問地址,那麼你能否有能力控制住哪些應用才能夠經過你搭建的cas伺服器 進行認證嗎?你可能會說,大家不會亂連,進行認證的。再想想一種情況,如果經過後臺監控,發現有一個應

彈出AlertDialog的時候報You need to use a Theme.AppCompat theme (or descendant) with this activity錯誤

今天遇到一個bug,用百度地圖的時候,我對上面的標註設定了點選監聽,設定的相應的反應是彈出一個AlertDialog 記錄一解決bug的歷程 但是Dialog卻沒有彈出來,一看AS下面,報了這錯,起初我看我gradle.app裡面 implementation 'com.android.suppo

對話方塊報錯 You need to use a Theme.AppCompat theme (or descendant) with this activity.

在跟著視訊學習安卓開發時候發現程式碼一致,結果我的卻報錯。 原因:我是用的開發環境為Androidstudio,視訊中使用的是eclipse。在Androidstudio中activity預設繼承的AppCompatActivity,只需要在Androidmanifest檔案中配

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

錯誤描述為: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 起因: 我想在Manifest中設定我的activity

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a

在設定隱藏標題欄的時候:出現以下錯誤 java.lang.IllegalStateException: You need to use a Theme. AppCompat theme (or des

按照官網寫的第一個APP,出現了You need to use a Theme.AppCompat theme (or descendant) with this activity問題

這是我第一次根據Android官網指導寫的APP,連結如下: 每一步都嚴格參照了官網指導,一步一步敲程式碼、執行,結果報瞭如下錯誤: 10-08 18:08:40.878 18503 18503 E AndroidRuntime: Caused by: java.la

You need to use a Theme.AppCompat theme (or descendant) with this activity解決方法

當我的MainActivity繼承自v7包中的ActionBarActivity或者AppCompatActivity時,如果在style.xml檔案中指定MainActivity所使用的樣式如下: <style name="AppTheme" parent="and

Material Design出現You need to use a Theme.AppCompat theme (or descendant) with this activity

You need to use a Theme.AppCompat theme (or descendant) with this activity問題 因為你雖然在Activtiy裡寫上了extends AppCompatActivity 但卻在Andro

Android實戰技巧Handler使用中可能引發的內存泄漏

sha 指向 ons har 引用 destroy 對象 from weak 問題描寫敘述 曾幾何時,我們用原來的辦法使用Handler時會有以下一段溫馨的提示: This Handler class should be static or le

Android實戰技巧Android原型設計工具探索

移動開發者、移動產品經理和互動設計師在有了產品的想法後會做出一系列的草圖,然後反覆推敲改進,直到自己滿意。這個草圖就是原型設計,是產品設計初期很重要的工作,它是產品的雛形,之後會以此為原型進行開發。 當移動網際網路熱度增加後,一些主打移動原型設計的工具如雨後春

性能測試環境部署Dubbo部署

密碼 pro 項目部 3.4 工作 zookeeper aps war 保存 Zookeeper部署 ZooKeeper是一個分布式的,開放源碼的分布式應用程序協調服務,是Google的Chubby一個開源的實現,是Hadoop和Hbase的重要組件。它是一個為分布式應用提

MongoDB學習MongoDB 新增Shard Server

    1、啟動一個新Shard Server 程序 [[email protected] ~]# mkdir /data/shard/s2 [[email protected] ~]# /Apps/mongo/bin/mongod --shardsvr

Android問題集錦getActionBar為null的解決以及ActionBar的Back鍵

我們用getActionBar獲得ActionBar例項,將其隱藏或做其他操作。 ActionBar actionBar = getActionBar(); 不過我這樣做了,但是actionBar是null。 問題是由Activity基類引起的,當使用Ap

Android實戰技巧橫豎屏切換

這幾年一直在做手機上和電視盒的App,幾乎沒有考慮過橫豎屏切換的問題。電視盒好說,橫屏不變,你要是給它設計個豎屏人家也沒機會使;而手機上的應用就不好說了,有些介面你設計了橫豎屏相容可能是為了表示你的功能強大。但是按照慣例,或許也是設計師圖省事,我們只是做一個方案

【Java並發編程】並發新特性—阻塞隊列和阻塞棧(含代碼)

err 退出 link rac gb2312 com void throws pbo 轉載請註明出處:http://blog.csdn.net/ns_code/article/details/17511147 阻塞隊列 阻塞隊列是Java 5並發新特性中的內容

Java經典編程題50道

amp for 進行 temp 編程 排序 ati static bubble 對10個數進行排序。 public class Example28 { public static void main(String[] args) { int[] s =