Set 2 different colors in a Button - java

I have a simple app with jokes. There are buttons where I set the text with this code:
bt_barjokes.setText(getString(R.string.bar_jokes)+ " ("+barjokes.size()+")");
Works perfectly and it gives the correct title and size of the used Arraylist: Bar Jokes (55)
The problem is I want to change the color and font size of (55):
("+barjokes.size()+")")
I have tried several of the suggested solutions in this forum but can't get it to work.

You can use ForegroundColorSpan to change text color, and AbsoluteSizeSpan or RelativeSizeSpan to change font size.

You can look #xizzhu 's answer, its ok additionally you can use SpannableString or Html.fromHtml
setText(Html.fromHtml("<font color=#343434>" +"<small>"+ "Little Black Text" +"</small>"+
"</font>"+"&nbsp&nbsp"+"<font color=#123456>" +"<big>" +"Big Blue Text" +"</big>"+ "</font>"));
#Edit : If you wanna use this in your button add this line in xml like: android:textAllCaps="false"
You can use : <small> or <big> , tested in Toolbar:
and in Button, its looking like :

Related

How to remove Autofill in inputType editText

How to remove this recommendation TAB with previously used email Id that appears when i click on the edit text . Email Tags
How to make that color TRANSPARENT once I've selected one them.Selected Color
You can use this in your xml to disable the auto fill
android:importantForAutofill="no"
if it doesn't work, could you please include your EditText xml

Edit text view with image and text wrapped around image

I am building a rich text editor.
I have implemented text formatting like bold italic etc and also paragraph formatting like blockQuote. Now I would like to add images in editor and text should wrap around it.
I have implemented all these using SpannableString() and Spanned() and StyleSpan().
I can add image to a line using ImageSpan(), but that add it inline and its just there in place of a character
, what I want is to insert it in paragraph and rest of text should wrap around it. I am able to add image at the beginning of text by following code.. but I cannot align it center and right.
SpannableString string = new SpannableString("Text with icon and padding");
string.setSpan(new IconMarginSpan(bitmap, 30), 0, string.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
How to do it ? any example? or what procedure to follow?
you can fulfill your requirement like below:
you can set your image in imageview and your text in Html.fromHtml("here put your text")
gradle file:
compile 'com.github.deano2390:FlowTextView:2.0.5'
your XML layout:
<uk.co.deanwild.flowtextview.FlowTextView
android:id="#+id/ftv"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="400dip"
android:padding="10dip"
android:src="#drawable/android2"/>
</uk.co.deanwild.flowtextview.FlowTextView>
your java file:
FlowTextView flowTextView = (FlowTextView) findViewById(R.id.ftv);
Spanned html = Html.fromHtml("here put your text");
flowTextView.setText(html);
you may get help by this link https://github.com/deano2390/FlowTextView also
I hope it help you..!
As per details given by you, It seems you might be using native EditText or you are trying with your custom EditText. Please provide this details to get exact solution of your query.
Apart from that, To build Rich Text Editor with the features mentioned by you (like Bold, Italic, Quote and Images etc), you can use this library RichEditor for Android: https://github.com/wasabeef/richeditor-android. It provides many features which may interest you.
Try with:
EditText text = (EditText)findViewById(R.id.text);
text.setCompoundDrawables(null, null, getResources().getDrawable(R.drawable.check_box), null);

Facebook LikeView change button size

I am using a LikeView in my android application and want to change the button size. Changing the view's size using layout parameters or the width/height at addView() does not help.
I'm using libGDX and have never worked with XML + libGDX, so a way to do it with code only would be nice!
Does anyone know how to do this? Currently I use the following code to create my LikeView:
likeButton = new LikeView(application);
likeButton.setLikeViewStyle(LikeView.Style.BUTTON);
likeButton.setX(x);
likeButton.setY(y);
likeButton.setObjectId(LIKE_URL);
likeButton.setVisibility(View.GONE);
application.layout.addView(likeButton,width,height);
likeButton.invalidate();
application.layout is a RelativeLayout
Try to create your LikeView from XML (or inflate this layout at runtime):
<com.facebook.widget.LikeView
android:id="#+id/button_like"
android:layout_height="31dp"
android:layout_width="wrap_content" />
I finally fixed it using setScale on the view. It's not the most elegant solution, but it does the job.
likeButton.setScaleX(1.8f);
likeButton.setScaleY(1.8f);

Open TextView links at another activity - custom ClickableSpan

I have a TextView with links and other text. I need to links to be clickable & I need to capture the click and open the link in a webview in my activity. I followed this this answer. My code looks like this:
actitivity_main.xml
<TextView android:id="#+id/textlinktest"
android:layout_width="wrap_content"
android:layout_height="50dp"/>
And this is the way I invoke it:
textLinkTest.setText(Html.fromHtml("Something else google"));
textLinkTest.setText(RichTextUtils.replaceAll(
(Spanned) textLinkTest.getText(),
URLSpan.class,
new URLSpanConverter()));
The links show up fine, but they are not clickable! The onclick in my customeclickablespan never gets called. I tried toggling android:linksClickable & also tried different values for android:autoLink. But the links remain unclickable. Any thoughts?
Add
textLinkTest.setMovementMethod(LinkMovementMethod.getInstance());
before
textLinkTest.setText(RichTextUtils.replaceAll((Spanned) textLinkTest.getText(), URLSpan.class, new URLSpanConverter()));

Android TextView Wrap

Here is my problem. How to make text don't wrap?
I already tried to make text smaller. Didn't work. Tried to do singleline="true". Here is what he do(2 screen shot 6-7 textview)
1 Screenshot) Here is I made it in the Eclipse
2 Screenshot) Here is how it showen in the emulator
Try setting android:ellipsize to none for each TextView. For more details see documentation on this attribute.
From xml:
<TextView ... android:ellipsize="none" />
From code:
TextView textView = new TextView(context);
...
textView.setEllipsize(null);
try giving android:maxLines=1... singleLine property should also work...

Categories

Resources