I have two questions
1) Does anyone know, how to apply styles or formatting to alert dialog. I currently use Builder builder = new AlertDialog.Builder(this);
And use setMessage()
method to set the content.
2) Also I would like to know how to change the color of the links created by linkify. I don't want the default blue color.
To do this you use alert builder to build your alert. You then get the TextView from this alert and then you set the typeface for the alert. That's good, remember to approve and upvote once you get the privileges so other people can get this help too.
AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout. DatePickerDialog or TimePickerDialog. A dialog with a pre-defined UI that allows the user to select a date or time.
A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for events that require users to take an action before they can proceed. In android, you can create following types of Dialogs: Alert Dialog.
Q1. You have to inflate or customize and create a style and apply to AlertDialog
Heres how you inflate a layout and apply it to AlertDialog
LayoutInflater li = LayoutInflater.from(ctx);
View view = li.inflate(R.layout.formatted_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle("Formatted");
builder.setView(view);
define all the formatting and styles required in the layout you specified.
You can access specific textview defined in the layout using inflated View i.e.
LayoutInflater li = LayoutInflater.from(ctx);
View view = li.inflate(R.layout.formatted_dialog, null);
TextView label=(TextView)view.findViewById(R.id.i_am_from_formatted_layout_lable);
Q2. android:textColorLink="#FF00FF"
can be used to specify color of link.
EDIT:
Sample layout saved as res/layout/link.xml:
<?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="fill_parent">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="http://www.google.com"
android:autoLink="web"
android:textColorLink="#FF00FF"
/>
</LinearLayout>
In your onCreate() or where or whenever you want to call AlertDialog
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.link, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Formatted");
builder.setView(view).create().show();
TextView text=(TextView) findViewById(R.id.text);
replace this
with context object if you are calling from some other method.
you can use following code to change typeface and Text color by extracting TextView from default alertDialog:
TextView txtAlertMsg = (TextView)alert.findViewById(android.R.id.message);
txtAlertMsg.setGravity(Gravity.CENTER);
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