Reputation: 412
I have shown a dialog fragment. I have done it, but I want to change background (Theme) color grey to white.
My dialog code:
public class TestDialog extends DialogFragment {
public static TestDialog newInstance() {
return new TestDialog();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialog);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return container;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//setStyle(DialogFragment.STYLE_NORMAL, R.style.MyDialog);
LayoutInflater inflater = getActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dailog_fragment, null))
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
TestDialog.this.getDialog().cancel();
}
});
return builder.create();
}
}
Upvotes: 2
Views: 4144
Reputation: 412
I Got The Solution:
I am using below style theme for set the white background color.
<style name="MyFragment">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:colorBackground">@android:color/white</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
We can also use Holo Theme
AlertDialog.Builder builder = new AlertDialog.Builder(ProfileEditActionBar.this, AlertDialog.THEME_HOLO_LIGHT);
Upvotes: 0
Reputation: 3307
In your manifest file, the activity definition of the dialog activity, add the android:theme
attribute as follows.
<activity
android:name=".YourActivityName"
android:theme="@styles/style"
/>
Upvotes: 0
Reputation: 4651
use this
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.MyDialog);
and then make the custom MyDialog
style.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="MyDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@color/orange_transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:gravity">center</item>
</style>
</resources>
note that it should be in style.xml
.
Upvotes: 1