This question already has answers here:
Is it possible to have multiple styles inside a TextView?
(20 answers)
Closed 9 years ago.
I am currently working on android project where I want to have a text view that contains two lines of code. I know I can just put a new line character in between to make it on a new line but I want to do a bit more than that.
Basically what I want achieve is on the first line I have text which uses the normal text design and on the next line the text will be styled differently, i.e. smaller and slightly different font colour.
I've tried searching for this and can't find anything anywhere.
Thanks for any help you can provide.
Option #1: Just use two TextView widgets in a vertical LinearLayout
Option #2: Use Html.fromHtml() to convert an HTML representation of what you want into a Spanned object that you can pass to setText()
Related
This question already has answers here:
Can you set graphical layout preview-only text on a TextView?
(2 answers)
Closed 5 years ago.
Is there a way to have text displayed in the preview pane in Android studio but not in the actual app while running on the phone?
I currently use the android:hint attribute, which is quite useful to see how much space a TextView requires or what size the text will be.
The problem, however, is that in case no text is assigned to the TextView, the hint shows in the app.
Is there a way to have the text display only in android studio but not at runtime?
It's tools:text="some text". This only will be visible in Android Studio.
From docs:
You can insert sample data in your layout preview by using the tools: prefix instead of android: with any attribute from the Android framework. This is useful when the attribute's value isn't populated until runtime but you want to see the effect beforehand, in the layout preview.
For example, if the android:text attribute value is set at runtime or you want to see the layout with a value different than the default, you can add tools:text to specify some text for the layout preview only.
I have looked high and possibly low to find this solution but it still doesn't seem to work. I keep looking for a solution but all i can find on google is " how to span TextViews"
Additional notes I have tried the following
Is it possible to have multiple styles inside a TextView?
Android: Coloring part of a string using TextView.setText()?
Android: Coloring part of a string using TextView.setText()?
This question already has answers here:
Why is my Button text forced to ALL CAPS on Lollipop?
(20 answers)
Closed 8 years ago.
I have a simple homescreen widget with a few buttons on it. My problem is that when the widgets are running on Lollipop the button's text are all capitalized, any previous Android version doesn't have this problem. The buttons in the layout.xml are very ordinary buttons: no styling or special sauce, just a width height and text size. The interesting thing is that any TextViews I place into the widget aren't affected by this in Lollipop, ie. it appears that only Button objects have this issue.
My AppWidgetProvider is pretty simple too: just sets the sets the text and a PendingIntent for each button.
It sounds like a global styling problem, but I can't find anything in my application's resources that would cause this. Does anyone have any input to this problem? Thanks!
You have 2 options :
1.Use android:textAllCaps="false" in your layout-v21 (or anywhere)
Programmatically change the transformation method of the button. mButton.setTransformationMethod(null);
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Android: Want to set custom fonts for whole application not runtime
I know there is way of doing it in the following way. But I want to apply the font to the entire application. Is that possible?
TextView txt = (TextView) findViewById(R.id.customfont);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Molot.otf");
txt.setTypeface(font);
Its not possible to give one for the entire application however, if you look at the accepted response on:
Android: Want to set custom fonts for whole application not runtime
they have a solution that makes it easier to set it to any view easier :) Another method is creating a custom widget to replace TextView, but if you require the font on other widgets too, it gets quite messy!
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do you rearrange buttons where you want them in Eclipse?
Hey guys I am having trouble with placing my buttons in my XML layout. I already have a background and was just trying to put 3 buttons near the middle and thats where I'm having trouble. I know about center gravity and all that but could you help me? Also, If I made my own buttons can I just import them using the image button thing, or is that not right? Thanks for the help!
You can rearrange elements of your layout by editing the XML directly or by dragging and dropping in the outline view or the graphical layout view (I find the latter harder to do reliably).
To use your custom views, click on the "Custom & Library Views" button in the graphical layout palette, or just type in the fully qualified class name as the view tag in the XML.