CalendarView gets white in Alert dialog - android

I am trying to implement a CalendarView in an AlertDialog. It works fine except for how the calendar turns completely white which leads to the numbers being barely readable and there are no lines between them. Does anybody have a clue why this is the case?
Here is my code:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CalendarView
android:id="#+id/calendarID"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="300dip"
android:tag="my tag" />
</FrameLayout>
and
public void onClickZumKalendar(final View view){
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
FrameLayout ll= (FrameLayout)inflater.inflate(R.layout.calendar_dialog, null, false);
new AlertDialog.Builder(this)
.setTitle("Title")
.setMessage("something")
.setView(ll)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//do nothing...yet
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
}
).show();
}

The property you want for the text color is:
android:focusedMonthDateColor
Here is an example edit to your code which results in a green background and large black text:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CalendarView
android:id="#+id/calendarID"
android:background="#color/light_green"
android:dateTextAppearance="#android:style/TextAppearance.Large"
android:focusedMonthDateColor="#color/black"
android:layout_width="match_parent"
android:layout_height="300dip"/>
</FrameLayout>

Related

How controll alertdialog button text size on android?

Hello senior developer.
recently I create alertdialog.
I know title size, message size controll
but I don't know controll button text size
How controll button text size ?
I must this format please
thanks.
View view = getLayoutInflater().inflate(R.layout.connecting_error_dialog, null);
TextView txtTitle = (TextView) view.findViewById(R.id.title);
txtTitle.setTextSize(40);
txtTitle.setTextColor(Color.RED);
txtTitle.setText("fail");
TextView message = (TextView) view.findViewById(R.id.message);
message.setTextSize(30);
message.setText("dddddd");
AlertDialog.Builder builder = new AlertDialog.Builder(Connectingreceiver.this);
builder.setView(view)
.setCancelable(false)
.setPositiveButton("ok",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
moveTaskToBack(true);
finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="HelloAlert!"/>
<TextView android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dip"/>
</LinearLayout>
The alert dialog needs to be created first and then it's elements become accessible to be changed.
final AlertDialog alert = builder.create();
alert.setOnShowListener(new DialogInterface.OnShowListener() {
#Override
public void onShow(DialogInterface dialog) {
Button btnPositive = alert.getButton(Dialog.BUTTON_POSITIVE);
btnPositive.setTextSize("desired font size");
Button btnNegative = alert.getButton(Dialog.BUTTON_NEGATIVE);
btnNegative.setTextSize("desired font size");
}
});
return alert;

AlertDialog text color and margin

I'm targeting API level 8+. I need a dialog with a title, a message, a checkbox with some text and two classic bottom buttons.
I'm trying to use a standard AlertDialog, and method setView to add the checkbox:
checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/frame_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<CheckBox
android:id="#+id/checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:checked="true"
android:textSize="14sp" >
</CheckBox>
</FrameLayout>
showDialog method
private void showDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("Title");
builder.setMessage("Message");
View checkboxView = View.inflate(activity, R.layout.checkbox, null);
CheckBox checkBox = (CheckBox) checkboxView.findViewById(R.id.checkbox);
checkBox.setText("Some checkbox text");
builder.setView(checkboxView);
// First button
builder.setNegativeButton(getString(R.string.not_now),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
});
// Second button
builder.setPositiveButton(getString(R.string.help),
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
});
builder.create();
builder.show();
}
My AppBaseTheme has parent "Theme.AppCompat.Light" (/res/values/styles.xml), the same for values-v11 and "Theme.AppCompat.Light.DarkActionBar" for values-v14.
I've problem in 2.3.3, checkbox and text have no margins or padding (I've set them in xml), besides text is black as the background. Everything looks fine in 4.4.
I've read a lot of things about this problem, but I'm still confused and without solution. Can you please help me?
You can force a white background of your dialog by using:
if(Build.VERSION.SDK_INT <= 10) {
builder.setInverseBackgroundForced(true);
}

Android Alert Dialog replace default blue with another color

I'm using a single choice alert dialog in which I'd like to replace the default blue (the title line and the radio buttons) to the orange that I am using in the title bar. I was able to change to the title bar using setCustomTitle(), but I am lost trying to get rid of this damn blue.
For the title bar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/orange" >
<TextView
android:id="#+id/alertTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="14dp"
android:gravity="center"
android:text="Alert Title"
android:textColor="#color/white"
android:textSize="18sp" />
</LinearLayout>
Building the AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
View customTitle = View.inflate(MainActivity.this, R.layout.custom_alert_title, null);
builder.setCustomTitle(customTitle);
builder.setSingleChoiceItems(mAlertOptions, -1, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// do stuff
dialog.dismiss();
}
}).create().show();
This is what it looks like
I need to get rid of this blue! Help!
The only way to change the title divider color is to use Resources.getIdentifier in combination with Window.findViewById. The checkmark can be easily changed by calling AlertDialog.Builder.setSingleChoiceItems(ListAdapter, int, OnClickListener).
Here's an example:
Single choice item layout
: I generated your_radio_button using Android Holo Colors.
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="#drawable/your_radio_button"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingEnd="16dip"
android:paddingStart="16dip"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorAlertDialogListItem" />
Implementation
final ListAdapter adapter = new ArrayAdapter<String>(this,
R.layout.select_dialog_singlechoice, android.R.id.text1, new String[] {
"Option 1", "Option 2"
});
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCustomTitle(getLayoutInflater().inflate(R.layout.custom_alert_title, null));
builder.setSingleChoiceItems(adapter, -1, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// Do something
}
});
// Show the AlertDialog
final AlertDialog dialog = builder.show();
// Change the title divider
final Resources res = getResources();
final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
final View titleDivider = dialog.findViewById(titleDividerId);
titleDivider.setBackgroundColor(res.getColor(android.R.color.holo_orange_dark));
Results

How can I access the EditText field in a DialogBox?

How can I access the EditText field in a DialogBox?
Place your EditText widget into your dialog:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/myEditText"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
Then inflate the View from within your Dialog and get the content of the EditText.
private Dialog myTextDialog() {
final View layout = View.inflate(this, R.layout.myDialog, null);
final EditText savedText = ((EditText) layout.findViewById(R.id.myEditText));
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(0);
builder.setPositiveButton("Save", new Dialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String myTextString = savedText.getText().toString().trim();
}
});
builder.setView(layout);
return builder.create();
}
After pressing the "Save"-button myTextString will hold the content of your EditText. You certainly need to display the dialog of this example first.

Android TimePicker looks cropped

I create a dialog box with TimePicker inside it. This works very well on portrait mode, however, once it is changed into landscape mode, the TimePicker minus button looks cropped.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time = " android:textSize="28dp"/>
<TimePicker android:id="#+id/PickTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/text1"
android:layout_alignLeft="#id/text1"/>
<Button android:id="#+id/StartStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:layout_below="#id/text1"
android:layout_toRightOf="#id/PickTime"/>
</RelativeLayout>
My code for displaying the dialog box:
LayoutInflater factory;
factory = LayoutInflater.from(this);
View textEntryView = factory.inflate(R.layout.test, null);
AlertDialog dialog = new AlertDialog.Builder(this)
// .setTitle("Auto-Shutdown Setting")
.setView(textEntryView)
.setPositiveButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
/* User clicked OK so do some stuff */
}
})
.create();
dialog.show();
TimePicker timePicker = (TimePicker) dialog.findViewById(R.id.PickTime);
timePicker.setIs24HourView(true);
timePicker.setCurrentHour(12);
timePicker.setCurrentMinute(15);
timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// ...
}
});
Anyone knows why this is happening? Is it possible to customize the size of the dialog box (make it bigger)? Any other solution would be appreciated.
Edit by JJD:
Since I have a similar case with a combined date and time picker layout in a ScrollView I want to add screenshots here. #lwijono Please feel free to remove them if they do not show what you originally described. Or leave a comment and I will do so.

Categories

Resources