Android unicode u23F8 (pause symbol) color - android

I can't change color of the u23F8 (pause symbol).
play symbol looks ok and I can change its color
playPauseButton = new Button(mContext);
playPauseButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 72);
playPauseButton.setTextColor(Color.WHITE);
...
if (mPlayer.isPlaying()) {
playPauseButton.setText("\u23F8");
} else {
playPauseButton.setText("\u25B6")
}

The TextView font renders \u23F8 and \u25B6 as an emoji, which means it basically uses a predefined image, so font colors are ignored on these.

Related

How to get color from buttons?

I need to find the red buttons on Activity and set orange background color to these buttons.
When I click on the button I set it to red:
view.setBackgroundTintList(ColorStateList.valueOf(Color.RED));
When I click on another button, the red buttons should turn orange.
public void Active(View view){
for (View but : buttons) {
but.setClickable(true);
but.setBackgroundTintList();
}
}
I do not know how to get the id of the colors
For me is unclear your question but I'll try to answer it.
Supposing buttons is a List<Button>, so what you can do is.
for(View but : buttons){
int color = ((ColorDrawable)but.getBackground()).getColor();
if(color == Color.Red){
//This button is red change it to orange
but.setBackgroundColor(R.colors.orange);
}
}
And when you are clicking the button use
button.setBackgroundResource(Color.Red);
but.setBackgroundColor(Color.RED);
use that

Android: Textview cannot be unbolded/italcized

A TextView is displayed in one activity and the user goes to another activity to edit the properties of the text such as color, size, bold, italics, and underlined. When the user chooses to make the text bold, italic, or bold_italic it works. If the user unselects the checkbox the TextView does not return to normal. It can shift between the styles (ie if I check bold, then uncheck bold and check italic the TextView will be italic, not bold) but it cannot have a normal TypeFace.
I've searched around and everything I've found says that using the setTypeface method with Typeface.NORMAL should work but it is not working.
I would appreciate some help in solving this. The relevant code is below. Thank you!
TextView mDisplayMessage = (TextView) findViewById(R.id.message);
mDisplayMessage.setTypeface(mDisplayMessage.getTypeface(), Typeface.NORMAL);
//TODO: Cannot return all the way back to normal. Remains bold/italic/bold_italic
if (mIsBold && mIsItalic) mDisplayMessage.setTypeface(mDisplayMessage.getTypeface(), Typeface.BOLD_ITALIC);
else if (mIsBold) mDisplayMessage.setTypeface(mDisplayMessage.getTypeface(), Typeface.BOLD);
else if (mIsItalic) mDisplayMessage.setTypeface(mDisplayMessage.getTypeface(), Typeface.ITALIC);
else mDisplayMessage.setTypeface(mDisplayMessage.getTypeface(), Typeface.NORMAL);
if (mIsUnderlined) {
mDisplayMessage.setPaintFlags(mDisplayMessage.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
} else {
mDisplayMessage.setPaintFlags(0);
}
If you didn't care about font family you can use
mDisplayMessage.setTypeface(Typeface.DEFAULT);
Because Typeface.DEFAULT change the font family(serif, sans-serif, monospace), but the below can keep the same font family with style changed.
Typeface typeface = mDisplayMessage.getTypeface();
int style = Typeface.NORMAL;
if(mIsBold && mIsItalic) {
style = Typeface.BOLD_ITALIC;
} else if(mIsBold) {
style = Typeface.BOLD;
} else if(mIsItalic) {
style = Typeface.ITALIC;
}
Typeface newTypeface = Typeface.create(typeface, style);
mDisplayMessage.setTypeface(newTypeface);
Try this,
mDisplayMessage.setTypeface(Typeface.DEFAULT);
OR
mDisplayMessage.setTypeface(null, Typeface.NORMAL);

change background and text color in AlertController android

How can we change the background and text color in AlertController?
Is there any way without using xml, so that we can add or modify here itself so that the color can be changed?
I was able to change color of bluetooth_discoverable but not able to change the background color in the top and down area where icon is present.
void createDialog(){
final AlertController.AlertParams p=mAlertParams;
p.mIconId=android.R.drawable.ic_dialog_info;
p.mTitle=getString(R.string.bluetooth_permission_request);
View view=getLayoutInflater().inflate(R.layout.bluetooth_discoverable,null);
p.mView=view;
TextView tv=(TextView)view.findViewById(R.id.message);
if (mEnableOnly) {
tv.setText(getString(R.string.bluetooth_ask_enablement));
}
else {
v.setText(getString(R.string.bluetooth_ask_enablement_and_discovery,mTimeout));
}
p.mPositiveButtonText=getString(R.string.yes);
p.mPositiveButtonListener=this;
p.mNegativeButtonText=getString(R.string.no);
p.mNegativeButtonListener=this;
setupAlert();
}

Android : Crouton lib and custom font

I use custom fonts in my app so i want a custom font for Crouton. I 've tried to do it with setTextAppearance, it doesn't work.
<?xml version="1.0" encoding="utf-8"?>
<com.ecab.ui.custom.TextViewCustomFont
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.crouton"
android:id="#+id/crouton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/ban_confirmation"
android:gravity="center"
android:text="TEST"
android:textColor="#android:color/white"
custom:typeface="gothamBold" />
In Style class :
INFOCUSTOM = new Builder().setDuration(3000).setTextAppearance(R.id.crouton).build();
Then, I've tried to do it by changing setTypeface() with my font, it doesn't work.
In Crouton class :
private TextView initializeTextView(final Resources resources) {
TextView text = new TextView(this.activity);
text.setId(TEXT_ID);
text.setText(this.text);
text.setTypeface(MyFonts.getGothamBookBold(this.activity));
Log.d(Constants.D_TAG, "chaneg the typeFace");
text.setGravity(this.style.gravity);
// set the text color if set
if (this.style.textColorResourceId != 0) {
text.setTextColor(resources.getColor(this.style.textColorResourceId));
}
// Set the text size. If the user has set a text size and text
// appearance, the text size in the text appearance
// will override this.
if (this.style.textSize != 0) {
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, this.style.textSize);
}
// Setup the shadow if requested
if (this.style.textShadowColorResId != 0) {
initializeTextViewShadow(resources, text);
}
// Set the text appearance
if (this.style.textAppearanceResId != 0) {
text.setTextAppearance(this.activity, this.style.textAppearanceResId);
}
return text;
}
What can i do to have a custom Font ?
ps : library version ==> 1.7
Okay, I found the problem !
It works with the second solution by changing the Typeface. I had just forget to remove the
setTextAppearance(R.id.crouton)
in the Style class. So my custom style is like this :
INFOCUSTOM = new Builder().setDuration(3000).setBackgroundDrawable(R.drawable.ban_confirmation).setHeight(LayoutParams.WRAP_CONTENT)
.build();
One problem resolves, another arrives :) ! With the background drawable, the text is not vertically center
You can a custom Style that uses the resourceId of your text
appearance via Style.Builder.setTextAppearance(...).
This takes a reference from your styles.xml and uses it within the
internal TextView of the Crouton.
Then you can call Crouton.makeText or Crouton.showText with your
custom Style.
Source
How does MyFonts.getGothamBookBold() look like?
This however should work:
private TextView initializeTextView(final Resources resources) {
TextView text = new TextView(this.activity);
text.setId(TEXT_ID);
text.setText(this.text);
Typeface myTypeFace = Typeface.createFromAsset(this.activity.getAssets(), "gothamBold.ttf");
text.setTypeface(myTypeFace);
text.setGravity(this.style.gravity);
// set the text color if set
if (this.style.textColorResourceId != 0) {
text.setTextColor(resources.getColor(this.style.textColorResourceId));
}

How to change textcolor of switch in Android

I'm creating an application which uses Android 4.0.
I'm wondering if it is possible to change the text color of the text in a switch.
I've tried setting the text color, but it doesn't work.
Any ideas?
Thanks in advance!
You must use android:switchTextAppearance attribute, eg:
android:switchTextAppearance="#style/SwitchTextAppearance"
and in styles:
<style name="SwitchTextAppearance" parent="#android:style/TextAppearance.Holo.Small">
<item name="android:textColor">#color/my_switch_color</item>
</style>
you can also do it in code, also using above styles:
mySwitch.setSwitchTextAppearance(getActivity(), R.style.SwitchTextAppearance);
...and as for setTextColor and Switch - this color will be used if your SwitchTextAppearance style doesn't provide a textColor
you can check it in Switch source code in setSwitchTextAppearance:
ColorStateList colors;
int ts;
colors = appearance.getColorStateList(com.android.internal.R.styleable.
TextAppearance_textColor);
if (colors != null) {
mTextColors = colors;
} else {
// If no color set in TextAppearance, default to the view's textColor
mTextColors = getTextColors();
}
ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable.
TextAppearance_textSize, 0);
if (ts != 0) {
if (ts != mTextPaint.getTextSize()) {
mTextPaint.setTextSize(ts);
requestLayout();
}
}
I think you have to look at the theme which you are using for your application. Because the color of the switch is the responsibility of the theme, afaik. So I would suggest you have a look on how you can change the settings of a theme. Or you could create a custom theme with the new colors.
TextView.setTextColor() takes an int representing the color (eg. 0xFFF5DC49) not the resource id from the xml file. In an activity, you can do something like:
textView1.setTextColor(getResources().getColor(R.color.mycolor))
outside of an activity you'll need a Context eg.
textView1.setTextColor(context.getResources().getColor(R.color.mycolor))
For more refer this

Categories

Resources