में चेतावनी डिलीग बनाने में असमर्थ मेरे पास Activity
है जो ActionBarActivity
बढ़ाता है। जब भी मैं उस में एक AlertDialog
बनाने का प्रयास करें, लाइन जहां संवाद इस त्रुटिएक्शनबैरएक्टिविटी
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
देने बनाई गई है लेकिन मैं पहले से ही Appcompat
विषय Theme.AppCompat.Light.NoActionBar
उपयोग कर रहा हूँ के रूप में मैं उपकरण पट्टी का उपयोग कर रहा पर दुर्घटनाओं। इसका क्या कारण रह सकता है?
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MyActivity extends ActionBarActivity {
Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comments);
toolbar = (Toolbar)findViewById(R.id.tool_bar_comment);
setSupportActionBar(toolbar);
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(getApplicationContext()).create();
alertDialog.setTitle("Network error");
alertDialog.setMessage("Check network connection and try again.");
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
alertDialog.show();
}
}
यहाँ मेरी mainfest फ़ाइल है::
<application
android:name=".Networking.AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
...
<activity
android:name=".MyActivity"
android:label="@string/myactivity"
>
</activity>
</application>
और, यहाँ styles.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
android:theme
में गतिविधि गुण जोड़ना है यहाँ मेरी गतिविधि है मेनफेस्ट ने बिल्कुल मदद नहीं की।
<activity
android:name=".MyActivity"
android:label="@string/myactivity"
android:theme="@style/Theme.AppCompat.NoActionBar"
>
संभव डुप्लिकेट के साथ यह गतिविधि] (http://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity) –
आपको उपयोग करने की आवश्यकता नहीं है एंड्रॉइड: थीम = "@ शैली/थीम.एप कॉम्पैक्ट.एक्शनएक्शनबार" बस एंड्रॉइड का उपयोग करें: थीम = "@ स्टाइल/ऐपथीम" – arjunkn