change the colour and font of text of title in dialog box - android

I want to change the font and colour of the title in dialog box, I want change font, size, and colour, what should I do?
here is my code,
ivworknggroup.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(Ourwork.this);
dialog.setContentView(R.layout.nggroup);
dialog.setTitle("N.G.GROUP");
TextView tvnggroup1 = (TextView) dialog.findViewById(R.id.tvnggroup1);
TextView tvnggroup2 =(TextView)dialog.findViewById(R.id.tvnggroup2);
Typeface typeFace1 = Typeface.createFromAsset(getAssets(),"fonts/antennalight.ttf");
tvnggroup1.setTypeface(typeFace1);
Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/antennabold.ttf");
tvnggroup2.setTypeface(typeFace);
tvnggroup2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.nggroupindia.com/"));
startActivity(browserIntent);
}
});
dialog.show();
}
});
can any one help me?
thank u.

Well i had a similar situation once, but this is what got it solved for me.
Dialog sortDialog = new Dialog(getApplicationContext());
sortDialog.setContentView(R.layout.adtype_alertdialog);
sortDialog.setTitle("N.G.GROUP");
int dividerId = sortDialog
.getContext()
.getResources()
.getIdentifier("android:id/titleDivider", null,
null);
if (dividerId != 0) {
View divider = sortDialog.findViewById(dividerId);
divider.setBackgroundColor(getResources().getColor(
R.color.yellow));
}
TextView tv = (TextView) sortDialog
.findViewById(android.R.id.title);
if (tv != null) {
tv.setTextColor(getResources().getColor(R.color.yellow));
}
sortDialog.show();
android:id/titleDivider & android.R.id.title in an identifier found in the alert_dialog.xml in your SDK folder

you should use custom view for title of your dialog maybe this link help you
how to include custom title view with in AlertDialog in android?

try this way
private String HALLOWEEN_ORANGE = "#FF7F27";
AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Message").show();
setTitle("Title").
setTitleColor(HALLOWEEN_ORANGE).
setDividerColor(HALLOWEEN_ORANGE).
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setTextSize(10);//to change font size
textView.setTextColor(Color.RED); // to change color
//to change font family
Typeface face = Typeface.createFromAsset(getAssets(),"font/fontFileName.ttf");
textView.setTypeface(face);

Related

Android AlertDialog title font

I am trying to change the font of android.support.v7.app.AlertDialogtitle text.
METHOD 1 :
TextView title = (TextView) dialog.findViewById(android.R.id.title); //returns null
METHOD 2 :
final int titleId = context.getResources().getIdentifier("alertTitle", "id", "android");
TextView title = (TextView) dialog.findViewById(titleId); //Also returns null.
Is there any other way to get the title TextView?
Please note I do not want to use a custom layout.
Thanks.
I got it to work using this solution :
final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
Typeface tf = //get the typeface.
CustomTFSpan tfSpan = new CustomTFSpan(tf);
SpannableString spannableString = new SpannableString(title);
spannableString.setSpan(tfSpan, 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
alertBuilder.setTitle(spannableString);
AlertDialog dialog = alertBuilder.create();
dialog.show();
CustomTFSpan
public class CustomTFSpan extends TypefaceSpan {
private Typeface typeface;
public CustomTFSpan(Typeface typeface) {
super("");
this.typeface = typeface;
}
#Override
public void updateDrawState(TextPaint ds) {
applyTypeFace(ds, typeface);
}
#Override
public void updateMeasureState(TextPaint paint) {
applyTypeFace(paint, typeface);
}
private static void applyTypeFace(Paint paint, Typeface tf) {
paint.setTypeface(tf);
}
}
Use this one
TextView title = (TextView) dialog.findViewById(R.id.alertTitle);
Without any custom title :)
Your question has already answer here : Change Title Font Of Alert Dialog Box Android
You can simply use a textview and set it as custom title like this : builder.setCustomTitle(tv2);
Create a simple TextView
TextView tv;
And replace
builder.setTitle("My Title");
with
builder.setCustomTitle(tv);

How to animate textview text in Android

I made animation for background colors of the text views like these:
final TextView textView1 =
(TextView)findViewById(R.id.leftleft);
Resources res = getResources();
final TransitionDrawable crossfaderView1 =
getTransitionDrawableFromColors(R.color.green, R.color.lime);
textView1.setBackground(crossfaderView1);
chooseChangeColors.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View v) {
if (somethingElseIsPressed == true) {
crossfaderView1.reverseTransition(timeForTransition);
}
else {
crossfaderView1.startTransition(timeForTransition);
}
somethingElseIsPressed = !somethingElseIsPressed;
}
});
But I want to make text in these textViews also changing its own color and text itself.
How can I achieve this?

Set Text for pop up

I have a button with the onClick name of checkResult.
public void checkResult(View view){
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
LinearLayout myRoot = new LinearLayout(this);
View popupView = layoutInflater.inflate(R.layout.layout_result_popup, myRoot);
final PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//what I want to show in the popup
TextView scorePopup = (TextView)findViewById(R.id.score_popup);
scorePopup.setText("Your score: " + score);
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(checkResultButton, 100, -1200);
popupWindow.setFocusable(true);
popupWindow.update();
}
When checkResult button is clicked, layout_result_popup is displayed.
I directly put a button at main activity and use onClick to show popup. So far, I managed to show the popup text in XML. But when I try to set some text to it, my app crashed.
Help please. :)
Try to replace those 2 lines with this:
runOnUiThread(new Runnable() {
#Override
public void run() {
TextView countView = (TextView)findViewById(R.id.count);
countView .setText("Count: " + count+ "/" + totalCount);
}
});
It very likely even works with the first line outside of the runOnUiThread

Android dialog title and divider color not changing

I have created custom Dialog.
I wants To change my Dialog title color and Divider line color.
I have gone through many answers but still M not successful.
I have tried different methods like:
int titleDividerId = resources.getIdentifier("titleDivider", "id", "android");
View titleDivider = dialog.getWindow().getDecorView().findViewById(titleDividerId);
titleDivider.setBackgroundColor(R.color.Red);
And used the following code:
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.alertdialog_caseadd);
dialog.setTitle("Add new court");
final Resources res = getResources();
final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
inal View titleDivider = dialog.findViewById(titleDividerId);
titleDivider.setBackgroundColor(res.getColor(android.R.color.holo_orange_dark));
dialog.getWindow().setBackgroundDrawableResource(R.drawable.alerttitle);
final EditText casetype= (EditText) dialog.findViewById(R.id.text);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
Button dialogButtoncancel = (Button) dialog.findViewById(R.id.dialogButtoncancel);
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(casetype.getText().toString().equals(""))
Alert.showError("Error", "Please enter case type", CaseType.this);
else
if(Network.isOnline(getApplicationContext()))
new WebTask().execute();
else
Alert.showNetworkError(CaseType.this,inflater);
dialog.dismiss();
}
});
dialog.show();
dialogButtoncancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
That above code is not working, divider line and title color shows in blue color only.
Please help me change it.
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.alertdialog_caseadd);
//this method help me for title color change
dialog.setTitle(Html.fromHtml("<font color='#FFFFFF'>Add new case stage</font>"));
//this method help me for divider color change
int dividerId = dialog.getContext().getResources().getIdentifier("android:id/titleDivider", null, null);
View divider = dialog.findViewById(dividerId);
divider.setBackgroundColor(getResources().getColor(R.color.white));

Transparent AlertDialog Android

I want to make my AlertDialog transparent, the following is my code and the line where it should be transparent just doesnt work.
AlertDialog.Builder builder;
AlertDialog alertDialog;
context = getActivity();
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.moreinfotable,null);
ListView list = (ListView) layout.findViewById(R.id.dialog_listView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
ViewImage.this.getActivity(), R.layout.interior_listview,
R.id.interior_list_text, values);
list.setAdapter(adapter);
builder = new AlertDialog.Builder(context);
builder.setView(layout);
alertDialog = builder.create();
//THE LINE THAT DOESNT WORK// alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.show();
can someone please help. Thank you.
This is what i want to do.
Use this way
alertDialog.show();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.argb(0, 200, 200, 200)));
I did this on custom alert dialog.
Values are like alpha, red, green, blue. Range from 0 to 255. Change values of alpha to get different degree of transparency
I don't know if this will help you. This is how i created my dialog box (its a prompt to user to try the app without log-in)
public void promptUser()
{
final Dialog requestDialog= new Dialog(MyActivity.this);
requestDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
requestDialog.setContentView(R.layout.lyt_prompt_user);
TextView requestTitle = (TextView) requestDialog.findViewById(R.id.request_title);
TextView requestText = (TextView) requestDialog.findViewById(R.id.request_text);
Button acceptButton = (Button) requestDialog.findViewById(R.id.request_accept);
Button rejectButton = (Button) requestDialog.findViewById(R.id.request_reject);
requestTitle.setText("Don't want to login?");
requestText.setText("You can still explore the app with limited functionality.");
acceptButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// do something
requestDialog.dismiss();
finish();
startActivity(intent);
}
});
rejectButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
requestDialog.dismiss();
(MyActivity.this).finish();
}
});
requestDialog.setCancelable(false);
requestDialog.show();
requestDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.argb(0, 200, 200, 200)));
}
I tried changing the alpha from 0 to 90, it shows a faint white background, somewhat glassy feeling.

Categories

Resources