I would like to add a picture before the text "Accessar" within the button. As the picture below.
I got the above effect in java class, I wonder if it is possible in xhtml.
<Button
android:id="#+id/login.button.cadastrese"
style="#style/ButtonsLogin"
android:background="#drawable/btn_login_cadastrese"
android:drawableLeft="#drawable/icon_login_cadastrese"
android:text="#string/login.btn.cadastre" />
work aligned to the button, not the text
Spannable buttonLabel = new SpannableString(getResources().getString(R.string.login_btn_acessar));
buttonLabel.setSpan(new ImageSpan(getApplicationContext(),R.drawable.icon_login_acessar, ImageSpan.ALIGN_BASELINE), 0, 1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
btnLogin.setText(buttonLabel);
Resolves, but is much line to little effect. Thus, I have to add the string underlin _Acessar
Related
I've searched something around here but nothing came up.
I'd like to have an EditText in which I can change attributes like color or dimension of a selected part.
I've already tried with the spannable thing, from another question:
TextView myTV = (TextView)findViewById(R.id.test);
String textString = "StackOverFlow Rocks!!!";
Spannable spanText = Spannable.Factory.getInstance().newSpannable(textString);
spanText.setSpan(new BackgroundColorSpan(0xFFFFFF00), 14, 19, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
myTV.setText(spanText);
I assume that I have to assign it to some onClick method..Also my problems are those two number, I should put some "selectedText" there instead I think.
Is this even possible?
I'd like to have an EditText in which I can change attributes like color or dimension of a selected part
If you want the user to "change attributes... of a selected part", my recently-updated RichEditText offers that. I do not have color or text size going yet, though, as those will need a toolbar (rather than my current action mode support).
Also my problems are those two number, I should put some "selectedText" there instead I think
You are probably looking for getSelectionStart() and getSelectionEnd().
i can set image textview rightside using xml attribute like
<TextView
android:id="#+id/txtarrow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/arrow"
android:gravity="right"
android:onClick="VideoClick"
android:padding="5dip"
android:textColor="#feb4e7" >
</TextView>
i want to set
android:drawableRight="#drawable/arrow"
programatically
like
txtarrow1.setBackgroundResource(R.drawable.arrow_blue);
but this one is not working
You can simply use Google to find the Android java docs of TextView.
They have a huge table showing every attribute's its programatical option.
android:drawableRight (#compile time)
setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) (#runtime)
The drawable to be drawn to the right of the text.
Here You want to use
Adding image on specific direction in Text View pro-grammatically
There are 2 method :
1> Through Image Drawable
ex:
Drawable img = getContext().getResources().getDrawable( R.drawable.dogy );
txtarrow1.setCompoundDrawablesWithIntrinsicBounds(
img,// left
null,//top
null,// right
null//bottom);
Remember this method is most use-full in image store in one view (Text View , Button)
2> Through Image Id
txtarrow1.setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_doggy,// left
0,//top
0,// right
0//bottom);
Most probably these method use in different images display in multiple view like (GridView)
Must remember difference between these two when Drawable can't show image set null & in ID set 0 (zero)
You can use SpannableString..
SpannableString text = new SpannableString("text");
text.setSpan(new ImageSpan(getActivity(), R.drawable.arrow_blue), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
txtarrow1.setText(text);
For EditText that going be filled with RTL text, is there a way to change the gravity of the error drawable (and popup of course) ?
here is an example of regular error drawable
so since the text entered is RTL i would like the pop up to show up at the LEFT side of the EditText
i tried to apply custom drawable , but Drawable doesnt seem to have any setGravity method.
thanks in advance.
It's not possible by normal means, however you can extend the Android TextView class and change the layout that Android uses to inflate the popup. I haven't tried this myself but it could work.
I did a quick look in the source of TextView and found this line
final TextView err = (TextView) inflater.inflate(com.android.internal.R.layout.textview_hint,
null);
Which references to this layout.
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/popup_inline_error"
android:textAppearance="?android:attr/textAppearanceSmallInverse"
/>
Adding gravity here could do the trick. A similar approach for the drawable could apply.
It's over a year, but if it helps anyone else, you can use:
myEdit.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_error, 0, 0, 0);
but it will stay until you remove it
myEdit.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
I can't seem to figure out a way to easily display a fraction in a textview. Let be more clear i need a fraction with a number over a number in a textview and then there should be able to add more text after that all in the same textview. I have seen this linke Android - displaying fractions using unicode
And the solution does not work great especially when playing it into a alertdialog the formating is lost.
I have also tried this
SpannableStringBuilder test = new SpannableStringBuilder();
SpannableString content = new SpannableString("3");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
test.append(content);
test.append("\n");
test.append("56");
This works great however if I need to add more to that line it will be displayed on the bottom and i need it on the top line. If i try to insert into the top line then the bottom line will move because the textview is centered (also it wont work by aligning the text view in any particular way since i may have text before the fraction).. *I do not want multiple textview
The solution was to use this html format from the link. However you must add a extra space on the top and bottom to keep it from being cut off.
SpannableStringBuilder test = new SpannableStringBuilder();
test.append("\n");
test.append(Html.fromHtml("<sup>5</sup>/<sub>9</sub>"));
test.append("\n");
My button's layout_width set to match_parent.
In order to display multi lines on the button, I tried:
insert '\n' into the text on button
set Singleline false set Maxlines to 2 or 3
convert html from Html.fromHtml
Nothing worked. '\n' showed up as a small square on the button while showing single line of text.
Does anybody have any idea why this is happening and how I can fix this?
UPDATE: I just found out I was using custom button that has its own text drawing. That's the reason. Sorry for the confusion. I just punished myself by banging my head.
If you're trying to add a new line in a layout XML file:
Use
(new line)
android:text="Hi
Hello"
If you're trying to add a new line in code, just use '\n', same as in any other text.
If you can't see the second line, it may be that your Button doesn't have enough height. IE, in my case, the layout containing the button had a fixed height that just happened to make my button perfectly display one line of text.
I just tried and it worked:
1) Define in ../res/values/strings.xml:
<string name="multilines">Line1Line1\nLine2Line2</string>
2) Refer it in the layout file:
<Button
android:id="#+id/btn_multilines"
android:text="#string/multilines"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</Button>
In case you want to do that programmaticaly you can use System.getProperty("line.separator") in the string to change lines.
Like this:
String mybuttontext=line1+System.getProperty("line.separator")+line2;
and then set this String as buttons text.