When using a checkbox with extra drawable (besides the one used for the checkbox) using drawableLeft, the two drawables overlapp one another.
There is nothing special about the checkbox settings, here:
<CheckBox android:id="#+id/low_priority_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/low_priority"
android:textColor="#color/primary_text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:drawableLeft="#drawable/ic_primary_priority_flag_low_medium"/>
Actual result:
Expected result:
This problem occurs with compileSdkVersion 22 on devices with API <= 16
By the way, using drawableRight works as it should.
Is this a bug in the framework?
Any workaround?
Add style (style="#android:style/Widget.Holo.Light.CompoundButton.CheckBox") for the checkbox, which can move the drawable to correct position. The only issue is the distance between drawable and text is bigger than normal case for devices with API <= 16.
One of my CheckBox xml is listed as the following:
<CheckBox
android:id="#+id/male_toilet_checkbox"
style="#android:style/Widget.Holo.Light.CompoundButton.CheckBox"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:drawableLeft="#drawable/m"
android:drawableStart="#drawable/m"
android:text="#string/male_toilet"
android:textSize="14sp"
android:textColor="#ff6c51ff"
app:layout_constraintTop_toBottomOf="#+id/split_line1" />
Related
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.
I recently included the RatingBar view into a layout and realized it is not compatible with Talkback (it is not accessible). How can I have a star rating view that takes into account Talkback users?
Here are some ideas for anyone else who ends up here. I'm using targetSdk=28 and the androidx libraries.
Problem 1: Talkback skips the RatingBar when announcing the content in a ViewGroup.
Solution: Add a TextView with the desired announcement. Make it 0dp, so it won't affect your layout. INVISIBLE or GONE won't work.
<TextView
android:layout_width="0dp"
android:layout_height="0dp"
android:text="4.1 of 5 stars"/>
Solution: Display the number of ratings, and add the stars to the contentDescription. (do it programmatically, though)
<TextView
android:id="#+id/ratingCountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="23"
android:contentDescription="4.1 of 5 stars from 23 users"/>
Problem 2: Tapping on a RatingBar to hear the value. contentDescription works in this case, and you can set it in code.
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="3.5"
android:stepSize="1"
android:contentDescription="4.1 of 5 stars"/>
Tapping and dragging on a RatingBar to change the value seems to work. It says 20%, 40%, 60%.
I found an example of what I need here:
https://github.com/google/iosched/blob/2017/lib/src/main/java/com/google/samples/apps/iosched/ui/widget/CustomRatingBar.java
I have some EditText and TextView inside a Fragment. On the XML layout of the fragment I have added the following in EditText and TextView:
android:textAlignment="center"
Then I have tested the app in the emulator, on virtual device with API 25, and all seems to work fine, the fragment is displayed as it looks in the design window, with the text centered in both the EditText and the TextView.
However, I have launched the app in my own phone Android 4.1.2 API 16 and also in another virtual device that I have also created with API 16 and now none of the 'EditText' or 'TextView' are respecting the textAlignment property, the text is just displayed aligned to the left side.
Any help?, I am looking around but I cannot find anything related to API 16 and problems like that with alignments.
You should use
android:gravity="center"
Place the object in the center of its container in both the vertical
and horizontal axis, not changing its size.
You can easily do that with below. As i mentioned in comment also.
<EditText
android:id="#+id/et_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ems="10"
android:gravity="center"
android:hint="Bio DAte aaaaaaaa"
android:imeOptions="actionDone"
android:inputType="text"
android:maxLines="3"
tools:ignore="RtlCompat" />
Check official documentation.
android:textAlignment="center" or its setter were introduced in API 17. So it won't work on earlier devices i.e. API 16.
Instead use android:gravity which should provide the same functionality both in EditText and TextView.
I am using AppCompatCheckBox in XML layout as given below,
<android.support.v7.widget.AppCompatCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="#+id/checkBox"
android:buttonTint="#color/appColor"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp" />
But the check box is not visible on device running 4.3. But CheckBox text is visible, but not the CheckBox. Whats wrong here?
I am following this link. See the answer with 5 Points.
I don’t know if this solves, but you don’t need to use AppCompatCheckBox; a simple CheckBox is enough.
The activity you are using, presumably an AppCompatActivity, automatically inflates layout checkboxes as AppCompatCheckBoxs.
AppCompat* widgets should be used only when creating views at runtime, e.g. new AppCompatCheckBox(context) or when subclassing.
I am Working on Project with inside i want to Use custome image for Checkbox checked/unchecked event.
inside my login xml i have write :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp" >
<CheckBox
android:id="#+id/chk_remember_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/checkbox_uncheked"
android:paddingLeft="5dp"
android:text="Remember Me"
android:textColor="#024d94"
android:textSize="12dp" />
</LinearLayout>
Here i have Used android:paddingLeft="5dp" for getting space between button and textview.
My Problem : i got two different views for 2.3 and 4.2
for Device that has xhdpi or below density or that has large screen i
am getting below screen (this one is perfect as i want ):
for Device that has hdpi or below density or that has normal/small
screen i am getting below screen :
Can anyone tellme where am i missing? or anything Wrong in my layout?
I want the same layout screen which i am getting for 4.2 device in normal/large screen devices.
Thanks in advance.
It appears that Checkbox already uses padding by default internally and overriding it with paddingLeft causes these issues. You should remove that property from your XML.
If you still want to adjust the padding, you will have to do so programatically. See this answer: https://stackoverflow.com/a/4038195/832776
To only apply it to >4.2 you can use the following, though I would test on emulators to make sure this issue isn't merely a problem with just your devices.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Give the fixed width to check box hopefully this can resolved your problem.
Don't give padding, it comes by default with Checkbox.