I am working on an Android application in which I want to set the text size of my dialog box. I have used the following code an XML for textview but it is only setting the size of my fields. I want to set the text size and color of my title as well.
final CharSequence[] items = { "Fake Request", "Abusive Language","Indecent Approach","Unacceptable Attitude","Dangerous Behavior",};
ArrayAdapter<CharSequence> itemsAdapter = new
ArrayAdapter<CharSequence> (this,
R.layout.menu_items, items);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("My Title");
builder.setIcon(R.drawable.icon);
builder.setAdapter(itemsAdapter, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item) {
switch(item) {
case 0:
//Mark as Beautiful
break;
case 1:
//Mark as Beautiful
break;
case 2:
//Mark as Not a Portrait
break;
case 3:
//Mark as Offensive
break;
case 4:
//Mark as Spam
break;
case 5:
//cancel
break;
}
}
}
);
builder.show();
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:layout_margin="5dip"
android:gravity="center_vertical"
android:textSize="5dip"
android:textColor="@color/red_theme"
android:typeface="normal"
android:lineSpacingExtra="0dip"/>
Go to File -> Settings, a new setting dialogue box will appear. Then go to Editor -> General. Now mark the checkbox Change font size with Ctrl + Mouse wheel and click on Apply button. Now to change your editor font size, you just have to press and hold Ctrl and rotate the Mouse wheel.
With Android 8.0 (API level 26) and higher, you can instruct a TextView to let the text size expand or contract automatically to fill its layout based on the TextView 's characteristics and boundaries. This setting makes it easier to optimize the text size on different screens with dynamic content.
If you want to do it all using styles:
<style name="MyDialog" parent="Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowTitleStyle">@style/DialogTitle</item>
</style>
<style name="DialogTitle" parent="TextAppearance.AppCompat.Large">
<item name="android:textSize">18sp</item>
</style>
And create your dialog as such
new AlertDialog.Builder(this, R.style.MyDialog);
//Use this code
TextView myMsg = new TextView(this);
myMsg.setText("Succesfully send!");
myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
myMsg.setTextSize(20);
myMsg.setTextColor(Color.WHITE);
//set custom title
builder.setCustomTitle(myMsg);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With