Q: Different themes are required by activity and fragment for dialog box I am trying to create a dialog box from a fragment(mainScreenFragment.java). There are many fragments that are called from MainActivity since I am using a tab view here so I am using HOLO theme for MainActivity but when I try to create an alert box, an error shows up in the fragment saying "                                                                     java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity."
Please tell me what to do!
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.coderahul.player">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <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:label="@string/app_name"
            android:theme="@android:style/Theme.Holo">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".songPlay">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>

        <service
            android:name=".MusicService"
            android:enabled="true" />

        <activity
            android:name=".mainScreen"
            android:label="@string/title_activity_main_screen"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".playlistScreen"
            android:label="@string/title_activity_playlist_screen"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".playlistManager"
            android:label="@string/title_activity_playlist_manager"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".genreScreen"
            android:label="@string/title_activity_genre_screen"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".genrelistManager"
            android:label="@string/title_activity_genrelist_manager"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".albumScreen"
            android:label="@string/title_activity_album_screen"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".albumScreenManager"
            android:label="@string/title_activity_album_screen_manager"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".artistScreen"
            android:label="@string/title_activity_artist_screen"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".artistManager"
            android:label="@string/title_activity_artist_manager"
            android:theme="@style/AppTheme.NoActionBar"></activity>
    </application>

</manifest>

styles.xml
<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>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

    <style name="MyDialogTheme" parent="Theme.AppCompat" />

</resources>

MainActivity.java
public class MainActivity extends FragmentActivity implements ActionBar.TabListener {

int check=0;
private ViewPager viewPager;
private tabViewAdapter tabPagerAdapter;
private ActionBar actionBar;
private String[] tabNames = { "Genres", "Playlists", "All Songs", "Albums", "Artists" };


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    tabPagerAdapter = new tabViewAdapter(getSupportFragmentManager());
    viewPager.setAdapter(tabPagerAdapter);
    viewPager.setOffscreenPageLimit(5);
    actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    for (int i = 0; i < 5 ; i++) {
        actionBar.addTab(actionBar.newTab().setText(tabNames[i])
                .setTabListener(this));
    }
    viewPager.setCurrentItem(2);
    actionBar.setSelectedNavigationItem(2);
    viewPager.setOnPageChangeListener(new OnPageChangeListener() {
        @Override
        public void onPageSelected(int postion) {
            check = postion;
            actionBar.setSelectedNavigationItem(postion);
        }
        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }
        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    viewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}

@Override
public void onBackPressed() {
    if((mainScreenFragment.menu).getVisibility()==View.VISIBLE)
        (mainScreenFragment.menu).setVisibility(View.INVISIBLE);
    else
        moveTaskToBack(true);
}
}

mainScreenFragment.java
private View.OnClickListener menuButton = new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        Log.v("CheckMENU", "Working!!");

        switch (v.getId()) {
            case R.id.add: {
                Log.v("CheckMENUAdd", "Working!!");

                final SQLiteDatabase mydatabase = getActivity().openOrCreateDatabase("beats_playlists", android.content.Context.MODE_PRIVATE, null);
                mydatabase.execSQL("CREATE TABLE IF NOT EXISTS playlists(playlistName VARCHAR PRIMARY KEY);");

                List<String> playlists = new ArrayList<String>();
                Cursor cursor = mydatabase.rawQuery("SELECT * FROM playlists", null);
                playlists.add("Create new");
                if(cursor.moveToFirst()) {
                    while(cursor.isAfterLast()==false) {
                        String name = cursor.getString(cursor
                                .getColumnIndex("playlistName"));

                        playlists.add(name);
                        cursor.moveToNext();
                    }
                }
                cursor.close();

                final CharSequence[] playlistsData = playlists.toArray(new String[playlists.size()]);
                final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.MyDialogTheme);
                dialogBuilder.setTitle("Add to playlist");
                dialogBuilder.setItems(playlistsData, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {
                        String selectedText = playlistsData[item].toString();

                        if(selectedText.equals("Create new")){
                            final String[] playlistName = {""};
                            AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
                            alertDialog.setTitle("Create new");

                            final EditText input = new EditText(getActivity());
                            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                                    LinearLayout.LayoutParams.MATCH_PARENT,
                                    LinearLayout.LayoutParams.MATCH_PARENT);
                            input.setLayoutParams(lp);
                            alertDialog.setView(input);

                            alertDialog.setPositiveButton("Create",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            playlistName[0] = input.getText().toString();
                                            if(!playlistName[0].equals("")) {
                                                try {
                                                    mydatabase.execSQL("INSERT INTO playlists VALUES(\'" + playlistName[0].trim() + "\');");
                                                    mydatabase.execSQL("CREATE TABLE " + playlistName[0].trim() + "(songPath varchar PRIMARY KEY)");
                                                    mydatabase.execSQL("INSERT INTO " + playlistName[0].trim() + " VALUES(\'" + songPath + "\');");
                                                }
                                                catch (Exception e) {
                                                    Toast.makeText(getActivity(),
                                                            "Playlist already exist", Toast.LENGTH_SHORT).show();
                                                }
                                            }
                                        }
                                    });

                            alertDialog.setNegativeButton("Cancel",
                                    new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.cancel();
                                        }
                                    });

                            alertDialog.show();
                        }

                        else {
                            try {
                                mydatabase.execSQL("INSERT INTO " + selectedText + " VALUES(\'" + songPath + "\');");
                            }
                            catch (Exception e){
                                Toast.makeText(getActivity(),
                                        "Track exists in this playlist", Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                });


                AlertDialog alertDialogObject = dialogBuilder.create();
                alertDialogObject.show();
                Window window = alertDialogObject.getWindow();
                window.setLayout(ActionBar.LayoutParams.MATCH_PARENT, 300);

                break;
            }
        }
    }
};

