I use three dialogs in my app, one DatePickerDialog in a dialogfragment, one dialogfragment with a custom layout through an alertdialog and one alertdialog without a dialogfragment. My dateopickerdialog looks like this. Notice the titlepart which is completely orange.
My second dialogfragmen does not have the titlepart covering the whole upper part of the window which I would like to have.
Here is the relevant part of my style.xml
<style name="ScheduleCompareTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryDarkColor</item>
<item name="colorAccent">@color/primaryLightColor</item>
<item name="android:dialogTheme">@style/ScheduleCompareDialogTheme</item>
<item name="android:alertDialogTheme">@style/ScheduleCompareDialogTheme</item>
</style>
<style name="ScheduleCompareDialogTheme">
<item name="android:windowTitleStyle">@style/ScheduleCompareDialogTitle</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowCloseOnTouchOutside">false</item>
<item name="android:buttonBarButtonStyle">@style/Widget.MaterialComponents.Button.TextButton</item>
</style>
<style name="ScheduleCompareDialogTitle">
<item name="android:background">@color/primaryLightColor</item>
<item name="android:textAppearance">@style/DialogWindowTitleText</item>
</style>
<style name="DialogWindowTitleText">
<item name="android:textColor">@color/primaryTextColor</item>
<item name="android:textSize">24sp</item>
</style>
The first part is my base theme, the second is the style used for dialogs and alertdialogs, the third part for the dialogtitle and the fourth for the title text. The styling works but somehow not the whole title area background is colored orange. Judging from the second picture I assumed there was some standard padding applied so I set the padding in the style name="ScheduleCompareDialogTheme"
to 0dp. This produced the following effect.
So it works but only for the toppadding. Setting the paddingLeft and paddingRight explicitly to 0 dp did not produce any results.
Searching the internet I found something using android:topDark
but this also produced no effect.
Does someone know how to extend the orange rectangle to cover the whole of the top area?
Aditionally I would like to mention that the datepickerdialog was already styled like it is shown just using the basetheme.
EDIT: This is the layoutfile for the customdialog. I removed some code which is not shown in the picture, but is used when someone with more rights uses the app.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
.......
<RadioButton
android:id="@+id/radio_teachers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Docenten" />
.......
<RadioButton
android:id="@+id/radio_students"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Leerlingen" />
........
<AutoCompleteTextView
android:id="@+id/acl_textinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:hint="Zoeknaam"
app:layout_constraintTop_toBottomOf="@id/check_own_properties"
app:layout_constraintLeft_toLeftOf="@id/check_own_properties"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="50dp"
android:dropDownHeight="150dp"
android:inputType="textNoSuggestions"/>
</android.support.constraint.ConstraintLayout>
And the relevant part of the dialogfragment
public class OverlaySchedulePickerDialogFragment extends DialogFragment
implements CompoundButton.OnCheckedChangeListener,
View.OnClickListener {
private final String DEBUGTAG = "ScheduleDialog";
private Context mContext;
private ScheduleViewModel mScheduleViewModel;
private AlertDialog mDialog;
//variables for the layout
RadioGroup radiogroupBranches, radiogroupMainLeft, radiogroupMainRight;
RadioButton radioTeachers,radioStudents,radioLocations,radioGroups;
List<RadioButton> radioBranches;
CheckBox checkOwnProperties;
AutoCompleteTextView aclInputvalue;
StringsAdapter aclAdapter;
.....
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
mScheduleViewModel = ViewModelProviders.of(getActivity()).get(ScheduleViewModel.class);
mScheduleViewModel.loadDataFromDB(Constants.GETBRANCHESFROMDB, null);
LayoutInflater inflater = getActivity().getLayoutInflater();
View fragmentLayout = inflater.inflate(R.layout.dialogfragment_secondschedulepicker, null);
//get references to the layoutelements
radiogroupMainLeft = fragmentLayout.findViewById(R.id.radiogroup_main_left);
radiogroupMainRight = fragmentLayout.findViewById(R.id.radiogroup_main_right);
radiogroupBranches = fragmentLayout.findViewById(R.id.radiogroup_branches);
radioTeachers = fragmentLayout.findViewById(R.id.radio_teachers);
radioStudents = fragmentLayout.findViewById(R.id.radio_students);
aclInputvalue = fragmentLayout.findViewById(R.id.acl_textinput);
//set listeners for the checkbox and radiobuttons
checkOwnProperties.setOnCheckedChangeListener(this);
radioStudents.setOnClickListener(this);
radioTeachers.setOnClickListener(this);
radioGroups.setOnClickListener(this);
radioLocations.setOnClickListener(this);
radioTeachers.performClick();
//set properties of the AutoCompleteText
aclAdapter = new StringsAdapter(mContext, R.layout.autocomplete_listitem,new ArrayList<>());
aclInputvalue.setAdapter(aclAdapter);
aclInputvalue.setThreshold(2);
aclInputvalue.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if(textView.getId() == aclInputvalue.getId() && actionId == IME_NULL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
if (mDialog.getButton(DialogInterface.BUTTON_POSITIVE).isEnabled()) {
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
return true;
} else {
if (aclAdapter.suggestions.size() > 0) {
String text = aclAdapter.suggestions.get(0);
aclInputvalue.setText(text);
aclInputvalue.setSelection(aclInputvalue.getText().length());
return true;
}
}
}
return false;
}
});
//add textWatcher to validate the entered text
aclInputvalue.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
String stringToValidate = editable.toString();
if(mStringList!=null) {
mDialog.getButton(DialogInterface.BUTTON_POSITIVE)
.setEnabled(mStringList.contains(stringToValidate));
}
}
});
//build the dialog
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext);
dialogBuilder.setView(fragmentLayout);
dialogBuilder.setTitle(R.string.overlayschedulepickerdialog_title);
dialogBuilder.setPositiveButton(R.string.dialog_positive_button_text, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//Input is valid so transfer to mScheduleViewModel and ask for secondSchedule
int position = mStringList.indexOf(aclInputvalue.getText().toString());
mScheduleViewModel.setOverlaySchedule(mScheduleType,position);
}
});
dialogBuilder.setNegativeButton(R.string.dialog_negative_button_text, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
mDialog = dialogBuilder.create();
mDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
}
});
return mDialog;
}
END EDIT