亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

BasicActivity 中的 AlertDialog 不起作用 Theme.AppCompat

BasicActivity 中的 AlertDialog 不起作用 Theme.AppCompat

胡說叔叔 2022-05-12 18:22:49
我有一個 BasicActivity,我想在用戶單擊浮動操作按鈕時顯示一個 AlertDialog。當我在 FAB 上計時時:應用程序因以下錯誤而停止:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.我試圖從(默認 BasicActivity)更改我的活動主題:android:theme="@style/AppTheme.NoActionBar"到android:theme="@style/Theme.AppCompat"但是當我打開它并出現此錯誤時,整個活動都會停止: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.我看到了很多關于這個錯誤的問題,但我仍然不明白。我只使用了一個默認活動 (BasicActivity),我想顯示一個簡單的 AlertDialog。顯現:<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 回答

?
長風秋雁

TA貢獻1757條經驗 獲得超7個贊

我得到了使用 [this] 關鍵字而不是 getApplicationContext() 的問題。當您使用 getApplicationContext() 時。它將應用應用程序的主題而不是活動。


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

                    }

                }

            });


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

TA貢獻1871條經驗 獲得超13個贊

在清單中


// 要顯示的活動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>

將此添加到清單文件中的應用程序標記


<application

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

</application>


查看完整回答
反對 回復 2022-05-12
  • 2 回答
  • 0 關注
  • 239 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號