I create my custom view for notification and use TextView instead of Action.
The problem is: I want the TextView to be displayed with default style (as in default notification), but the TextView is displayed in different style.
So I need to know exactly the font-size, font-family of the default style. If I know these values, I can set them as the style of TextView.
Can anybody help me?
Use android:paddingLeft="8dp" for the text SHARE and decrease textSize by 1sp or 2sp.
Basically, the font size used are as follows :
micro : 12sp
small : 14sp
medium : 18sp
large : 22sp
Related
which text styles are used for the titles and subtitles in the Settings app? I tried using the following, but none of these produced the same result.
Title text
android:textAppearance="?android:titleTextAppearance"
android:textAppearance="?attr/title"
Subtitle text
android:textAppearance="?android:subtitleTextAppearance"
android:textAppearance="?attr/subtitle"
Text style is often not enough to achieve a particular style, you often need to set color too. In this case, I suspect they use Google Material Components styles. It's hard to judge the appropriate font size here given your font scale, but here's what I think they use:
Title
android:textAppearance="?textAppearanceBody1"
Subtitle
android:textAppearance="?textAppearanceBody2"
android:textColor="#color/material_on_background_emphasis_medium"
They also use a special font.
In my application I am using a style for textViews with distinct textSize. However based on different device's screen size, I have to change the textSize of all the textView. I can't call all the textViews one by one and change the textSize based on the screen size. So is there any way I can change the style attribute programatically based on the required conditions so that I don't have to set the text size individually?I think people have already asked this questions many times. Still I was unable to find an exact answer for my query.
You could use HTML in your TextViews.
textview.setText(Html.fromHtml("<h2>Title</h2><br><p>This is <b>bold</b> <font size="6">this is smaller</font>,<font size="20">this is bigger</font></p>"));
Output:
TitleThis is bold this is smaller,this is bigger
I want to change the textsize inside a style at run time. Can anyone suggest me how to achieve it. Here is the style "TitleView" in which textsize attribute is defined. I want to change it from 20sp to any other value at run time.
<style name="TitleView">
<item name="android:textSize">20sp</item>
</style>
I want to do it because I've 4 types of textview with different textsize. and In my app user can choose the textsize. So I've changed the text size of other view in relative to the user entered textsize.
Thanks in advance.
You cannot change style attribute at run time.
If you are just trying to change the text size just do:
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
this will change your text size and you can do this at any time you want. It is not necessary to change your style attribute. For setting text size at runtime see this
Edit: The poster has altered the original question. This answer is no longer directly applicable.
This cannot be done. The styles along with all the other resource values are all compiled into R.java at compile time.
Instead you could you create two styles and switch the style at runtime using setTextAppearance
I have 3 text views.
I need to set their weight as Light, Regular and Condensed.
Can someone help me on how to achieve this in Android?
Use android:textStyle on a TextView to set the text style like bold, italic or normal.
Here is an example of a TextView with a bold text style:
<TextView
android:id="#+id/hello_world"
android:text="hello world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"/>
If you want to use light or condensed, you will have to change your font. You can do it like this:
android:fontFamily="sans-serif-light"
For more information about fonts, please also look at the following answer Valid values for android:fontFamily and what they map to?
You can only show a TextView as Light, Regular and Condensed if the font that you're referencing allows those styles.
For example, if you import a font into your project and it doesn't have Light or Condensed, I don't think it's (dare I say) possible to make the text appear with that style in your TextView. If you are importing your own font, work with it programmatically e.g. In your activity declare a global TextView:
private TextView tv;
Then in onCreate(), reference the fontfile you save in /assets:
Typeface someFontName-condensed = Typeface.createFromAsset(getAssets(), "assets/NameOfFont-condensed.ttf");
tv = (TextView) findViewById(R.id.myTextViewId);
tv.setTypeface(someFontName-condensed);
Notice that I imported the condensed version of my font file (as .ttf), not as a packaged font .ttc. You can bring in various style versions of a font, but you should bring them in as individual .ttf files instead of one packaged file because you will want to reference the specific style .ttf.
However, if you're using a system font that allows you to reference various styles from your xml, see what they say here:
Valid values for android:fontFamily and what they map to?
As they say, for something like Roboto, you'll use the fontFamily.
I need to use a custom font (VAG Rounded, probably not relevant) but the font changes how my TextViews react.
In the image below, you can see the two textviews with a black background. The left one use the custom font, the right one the default system font (Roboto ?). Both of them have the same xml properties and size, but the padding is not the same and more important, the left one isn't centered vartically !
How can I make the TextView draw its content well centered ?
You can try to remove your customs font padding from your text style (styles.xml):
<item name="android:includeFontPadding">false</item>
If this still doesn't work, i would set a general padding in your styles xml.
I think that you have to set android:layout_height="match_parent" and then also android:gravity="center"
then if you post also your source code we can give you more information
I could not change the font, and I wasn't going to edit each character using an editor (I don't even know what I should have done to fix it).
Si I ended up measure the difference with the default font and I added 0.15f * fontSize in the padding top...