Downloadable font not displaying for Switch TextView - android

I'm using downloadable fonts for an app, and it's working just fine, however when I've tried to apply the font to the TextView of a Switch, my device won't display it and resorts to the default font - it displays the font correctly for TextViews in the same activity outside of the Switch component.
Strangely, the Android Studio layout design window shows the correct font, but when running on device, it doesn't seem to work correctly.
<Switch
android:id="#+id/switch1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:fontFamily="#font/baloo_bhai"
android:text="This is a switch"
android:theme="#style/AppTheme.Switch"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editText2" />
This is the display in Android Studio:
This is from my device:

It transpires this is a known issue Google Issue #63250768
A fix was located in another StackOverflow question however downloadable fonts will not work with this method - until a resolution, font files must be embedded into the application, as .XML fonts will not work.
Great job, Google!

Related

Android Studio shuts down when adding android:text attribute to any element in any xml layout file

I'm encountering a weird issue that started over night. If I open any xml layout file with the line
android:text="whatever" in an element, Android Studio immediately shuts down with no errors displayed.
Android Studio works perfectly fine for any other tasks. I've been going through similar questions and trying solutions with no success, until manually typing I noticed THIS attribute is causing the crash.
For example,
<TextView
android:id="#+id/emailtextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
works perfectly.
But when the line android:text="TextView" is added even manually the programs shuts down.
The same happens with buttons.
I can even run the app but I can't edit the xml from Android Studio.
Why might this be?

How do I scale my text size for multi-device compatibility on Android Studio?

I am having trouble scaling my text size based on the user's device. I use constraint layout to constrain the TextViews. I found that autoTextSize could be used to automatically fit my text in the TextViews. However, when I run my code on an Emulator like BlueStacks, some texts are not scaled properly. Weirdly, some work but some do not, even though I am implementing it the same way.
This is an example of what it looks like: The register button is in a big font but other texts aren't
This is what it looks like on my layout Editor:
My code for the register button:
<TextView
android:id="#+id/register"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="REGISTER"
app:autoSizeTextType="uniform"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="5:1"
app:layout_constraintEnd_toEndOf="#id/guideline3"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#id/guideline2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.541" />
my code for the "up to 8 characters" text.
<TextView
android:id="#+id/req"
android:layout_width="0dp"
android:layout_height="0dp"
android:autoSizeTextType="uniform"
android:text="*up to 8 characters"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="7:1"
app:layout_constraintEnd_toEndOf="#+id/guideline5"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/guideline4"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.538" />
Am I misusing autoSizeTextType somehow?
Also, my "Enter Username" text is very small. I use EditText and implement it the same way I did for the other two texts. If there is anyway I can make the font size bigger to fit the layout size, please let me know.
your <TextView android:id="#+id/register" is using app:autoSizeTextType="uniform" attr, <TextView android:id="#+id/req" have android:autoSizeTextType="uniform" - note the difference app/android. try to consolidate this param, you should probably use app in both/all TextViews
note that setAutoSizeTextTypeWithDefaults was introduced in API 26, so when you use android: prefix then this attr will be respected only on 26+. using custom app: makes this attr usable for TextView (in fact TextViewCompat) on any OS version
in Android Studio above layout preview you have an option to switch "Device to preview" and also API version - try to change to some older (in this sample 25 at most, preferably lowest supported minSdkVersion) or newest OS version, IDE should catch and show differences in look
Use TextView params like this
android:autoSizeTextType="uniform"
android:autoSizeMinTextSize="12sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="2sp"
You can check the official documentation for more info.

Some Font Characters Doesn't Seem Properly On Android?

For Android and IOS platforms same font used. It's looking good on IOS, but android doesn't show some characters like "Ş", "Ğ" properly.The below screenshot from android.
Seems it's not font specific problem beacuse on IOS working well.
<TextView
android:id="#+id/txt_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="#font/avenirltstd_book"
android:text="Şikayet Grafiği"
android:textColor="#color/white"
android:textSize="#dimen/dp18" />
Is there any special way to show these characters with same font? Or the solution is to stop dealing with this and use different font ?
check this post for setting special characters in xml file and this if you want to set using java language

Android Switch widget textOn and textOff not working in Lollipop

The behavior of the switch widget changed in Lollipop (5.0).
<Switch
android:id="#+id/switcher"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="16dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:layout_toEndOf="#id/another_view"
android:layout_toRightOf="#id/another_view"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:textOff="#string/disabled"
android:textOn="#string/enabled"
android:fontFamily="sans-serif-condensed"
/>
Rendered switch when targetSdkVersion=19:
Rendered switch when targetSdkVersion=21:
Note that preview rendering in Android Studio still produces a switch with text, but the switch loses it's text when an apk built with targetSdkVersion=21 is run on a device with Lollipop (Nexus 5). Running an apk built with targetSdkVersion=19 on the same Lollipop device renders the switch properly with text as expected.
Why? Any suggested workarounds?
Text is not shown by default under Material theme since the switch widget assets don't work well with text. Any text that you do set will be used to describe the content to accessibility services.
You can change this using the android:showText property or Switch.setShowText(boolean) method.
<Switch
...
android:showText="true" />
If you are using AppCompat switches, use app:showText instead.

TextView gets clipped on Samsung devices using Helvetica S font

I've got an ordinary TextView working correctly on all phones except on certain Samsung devices (Galaxy S2 and S3 for the moment, according to user feedback) and only when using the Helvetica S font (other pre-installed Samsung fonts work correctly).
The problem is that the text gets clipped a bit on the right, instead of wrapping correctly. I still cannot post images, but the issue is the same that happens in this question: Android text gets clipped on some devices (and with the difference that I'm not using Hindi fonts).
This is my TextView and its layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="24dp"
android:paddingBottom="32dp"
android:paddingLeft="#dimen/general_padding_sides"
android:paddingRight="#dimen/general_padding_sides"
>
<TextView
android:id="#+id/help_01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/help_text_size"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
/>
I tried setting clipToPadding to false on the layout to see if the clipped text could be seen, but the text gets clipped the same way, and I can't make any tests in situ as I don't have any Samsung test device yet (I depend on user feedback).
The thing is I couldn't find any other reference to this problem apart from the question linked above, but if there is a bug with Helvetica S in Samsung devices, I guess someone else should have faced this problem before.
Has anyone encountered this problem? Is there any xml property that I am missing and could prevent this behavior or is this just a Samsung bug?

Categories

Resources