第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

BasicActivity 中的 AlertDialog 不起作用 Theme.AppCompat

BasicActivity 中的 AlertDialog 不起作用 Theme.AppCompat

胡說叔叔 2022-05-12 18:22:49
我有一個(gè) BasicActivity,我想在用戶單擊浮動(dòng)操作按鈕時(shí)顯示一個(gè) AlertDialog。當(dāng)我在 FAB 上計(jì)時(shí)時(shí):應(yīng)用程序因以下錯(cuò)誤而停止:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.我試圖從(默認(rèn) BasicActivity)更改我的活動(dòng)主題:android:theme="@style/AppTheme.NoActionBar"到android:theme="@style/Theme.AppCompat"但是當(dāng)我打開它并出現(xiàn)此錯(cuò)誤時(shí),整個(gè)活動(dòng)都會(huì)停止:This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.我看到了很多關(guān)于這個(gè)錯(cuò)誤的問題,但我仍然不明白。我只使用了一個(gè)默認(rèn)活動(dòng) (BasicActivity),我想顯示一個(gè)簡單的 AlertDialog。顯現(xiàn):<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:label="@string/title_activity_main"        android:theme="@style/AppTheme.NoActionBar">        <intent-filter>            <action android:name="android.intent.action.MAIN" />            <category android:name="android.intent.category.LAUNCHER" />        </intent-filter>    </activity>    <activity        android:name=".ListActivity"        android:label="@string/title_activity_list"        android:launchMode="singleTop"        android:theme="@style/AppTheme.NoActionBar"        />    <activity        android:name=".AddActivity"        android:label="@string/title_activity_add"        android:theme="@style/AppTheme.NoActionBar">    </activity>    <activity        android:name=".DetailsActivity"        android:label="@string/title_activity_details"        android:parentActivityName=".ListActivity"        android:theme="@style/AppTheme.NoActionBar">        <!-- Parent activity meta-data to support 4.0 and lower -->        <meta-data            android:name="android.support.PARENT_ACTIVITY"            android:value=".MainActivity" />    </activity></application>
查看完整描述

2 回答

?
長風(fēng)秋雁

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超7個(gè)贊

我得到了使用 [this] 關(guān)鍵字而不是 getApplicationContext() 的問題。當(dāng)您使用 getApplicationContext() 時(shí)。它將應(yīng)用應(yīng)用程序的主題而不是活動(dòng)。


 AlertDialog.Builder builder = new 

 AlertDialog.Builder(this);

            builder.setIcon(android.R.drawable.ic_dialog_alert);

            builder.setTitle("MyTitle");

            builder.setMessage("MyMessage);

            builder.setCancelable(false);

            builder.setPositiveButton("SAVE", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int id) {

                    if (dialog != null) {

                        dialog.dismiss();

                    }

                }

            });


查看完整回答
反對 回復(fù) 2022-05-12
?
慕桂英4014372

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊

在清單中


// 要顯示的活動(dòng)toolbar


    <activity android:name=".YourActivity"  

     android:theme="@style/AppTheme.NoActionBar"><!-- ADD THIS LINE -->

在樣式.xml


<style name="AppTheme.NoActionBar">

    <item name="windowActionBar">false</item>

    <item name="windowNoTitle">true</item>

</style>

將此添加到清單文件中的應(yīng)用程序標(biāo)記


<application

    android:theme="@style/Theme.AppCompat.Light"

</application>


查看完整回答
反對 回復(fù) 2022-05-12
  • 2 回答
  • 0 關(guān)注
  • 254 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號