I also tried to open a dialogue of my fragment with another topic in my activity and follow this decision . Like some of the people mentioned in the comments, I did not get him to work, and the dialogue continued to show the topic indicated in the manifest. The problem was that I built the dialog using AlertDialog.Builder in the AlertDialog.Builder method and therefore did not use the onCreateView method, as shown in the answer I linked to. And when I instantiated AlertDialog.Builder , I walked in context using getActivity() when I had to use the ConstextThemeWrapper instance instead.
Here is the code of my onCreateDialog:
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Create ContextThemeWrapper from the original Activity Context ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(getActivity(), android.R.style.Theme_DeviceDefault_Light_Dialog); LayoutInflater inflater = getActivity().getLayoutInflater().cloneInContext(contextThemeWrapper); // Now take note of the parameter passed into AlertDialog.Builder constructor AlertDialog.Builder builder = new AlertDialog.Builder(contextThemeWrapper); View view = inflater.inflate(R.layout.set_server_dialog, null); mEditText = (EditText) view.findViewById(R.id.txt_server); mEditText.requestFocus(); // Show soft keyboard automatically mEditText.setOnEditorActionListener(this); builder.setView(view); builder.setTitle(R.string.server_dialog); builder.setPositiveButton(android.R.string.ok, this); Dialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); return dialog; }
I originally created AlertDialog.Builder as follows:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
which I changed to:
AlertDialog.Builder builder = new AlertDialog.Builder(contextThemeWrapper);
After this change, the fragment dialog was displayed with the correct theme. Therefore, if someone has a similar problem and uses AlertDialog.Builder , then check the context passed to the builder. Hope this helps! :)
BruceHill Jul 18 '14 at 23:24 2014-07-18 23:24
source share