Android Studio Edit Text prints wrong input in the Emulator - android-studio

When I provide input to the Edit Text from my Laptop Keyboard, it prints (takes wrong input) jargon.
For example typing "London" from my Keyboard prints "øóñðóñ". The number "12345" print as "²²¤€"
I have tried changing the Edit Text multiple times but no use. The input from the emulator keyboard prints just fine. There was no error like this a few hours ago.
The code for Edit Text xml:
<EditText
android:id="#+id/cityText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="80dp"
android:layout_marginRight="80dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />

Solved it. Some combination of Ctrl+Alt+Shift+Left Arrow Key works!

Related

How to remove box and add only underline like the old style for android TextInputLayout in android studio

I want to create the following without setting the style to legacy because it creates other problems for example for AutoCompleteTextView.
style="#style/Widget.Design.TextInputLayout"
You can use app:boxBackgroundColor="#android:color/transparent" on FilledBox style TextInputLayout to only have an underline without the box.
Like this :
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/outlinedTextField"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:boxBackgroundColor="#android:color/transparent"
android:hint="label">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
And if you want to remove both box and underline use this : app:boxBackgroundMode="none"

Want to mix layout_centerHorizontal with layout_toLeftOf

I am struggling with a specific layout requirement.
I want a TextView that it centred. It is single-line and uses ellipsis if the text is too long. On the same line, to the right of it, I want a small ImageView. The presence of the ImageView must not affect what the TextView thinks is the horizontal centre of the layout. So, although the text might be centred, there is actually less space available to the right of the centre line than to its left.
Within a RelativeLayout, the sort-of intuitive thing to use is:
<ImageView
android:id="#+id/image_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/text_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/image_view_id"
android:layout_centerHorizontal="true"
android:singleLine="true"
android:ellipsize="middle" />
but this does not work because you cannot have both android:layout_toLeftOf and android:layout_centerHorizontal. It behaves as if the android:layout_centerHorizontal was not there.
I have also tried using a LinearLayout with android:layout_gravity without success. Is it possible?
It turns out that something close to what I want to achieve is very simple:
<ImageView
android:id="#+id/image_view_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/text_view_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/image_view_id"
android:layout_marginLeft="#dimen/size_of_image_view"
android:singleLine="true"
android:gravity="center"
android:ellipsize="middle" />
Using android:gravity="center" with android:layout_width="match_parent" centres the text in the available space. It is not perfect as the marginLeft is there to keep the text centred within the full layout, thus robbing a little space from its left end but it is good enough for my purposes.

Making two textviews with different font sizes have independent lines

I just started android app programming, so this might be a very dumb question, but I can't find the answer anywhere.
I want to have two textviews next to each other, where one shows three lines in a small font and the other contains a number in a very big font (which is as big as the three lines of the other textview). What now happens is that the first line of the textview with the smaller font sizes is aligned to the line of the other textview on the base line. So, I get some whitespace above the first line, because the font size is much smaller, and the three lines don't fit because so much space is wasted.
My code looks like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/historytextviewId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="#+id/countertextViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="60sp" />
</LinearLayout>
What I want is that the left textview just acts as if the other textview had the same font size.
EDIT: For some reason, replacing android:layout_height="wrap_content" by android:layout_height="fill_parent" in the first TextView worked for me (which I tried because I found some almost completely unrelated question where that was the answer), but I still don't get why that works.

Ellipsize Radio button label in Android

I am working on an Android native app where I have a radio button group as given below side by side.
[radio btn] Option 1 [radio btn] Option 2
Now the problem is I'm supporting few languages and the radio btn labels are larger in some languages. Hence I want to ellipsize these labels so that they are always aligned on a single line. Any suggestions.
You can use android:ellipsize="end" and android:singleLine="true" properties as below,
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true" />

TextView setEllipsize with text that have whitespaces

I'm using a TextView element with following layout settings
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLines="1" android:lines="1"
android:ellipsize="end"
android:text="AAAAAAAAA AAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"/>
As you can see I'm trying to add triple dot to the end of the long text, but for some reason all it does with texts that contain whitespaces is to cut the phrase without putting any dots in the end. Is there any workaround for this issue ?
Thanks.
UPD:it actually drops everything after the whitespace on the next line. This is strange regarding the fact that android:maxLines="1" android:lines="1".
Use the attribute: android:singleLine="true".
You can remove your android:maxLines="1" and android:lines="1" attributes afterwards.

Resources