Icon location problem with drawable Start in Android Studio - java

I have an editetext and I used drawable start, but the icon is not in the right place during execution
Inside view of Android Studio
Run the program
First I put a scrollview, then a LinearLayout, inside it is a ConstraintLayout, then editText.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity.Activityy.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="32dp"
android:text="Hi Rechard"
android:textColor="#FF6D00"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="27dp"
android:layout_marginTop="8dp"
android:text="#string/order_eat"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/textView"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="82dp"
android:layout_height="78dp"
android:layout_marginEnd="32dp"
android:src="#drawable/_f5736be590fe78e73bc4e4d7c012dda"
app:layout_constraintBottom_toBottomOf="#+id/textView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/textView" />
<EditText
android:id="#+id/editTextTextPersonName"
android:layout_width="315dp"
android:layout_height="68dp"
android:layout_marginStart="8dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="8dp"
android:background="#drawable/search_background"
android:drawableStart="#drawable/icons8_search_32"
android:drawablePadding="10dp"
android:ems="10"
android:hint="Find Your Food"
android:inputType="textPersonName"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
Inside the execution, the texts have also moved to the right, while they are on the left side of the design.

in android start means left and end means right
you must use android:drawableEnd="ICON" instead of android:drawableStart="ICON" to set icon right side.

My phone's language is right, but my design is left, so when I run, it is automatically directed to the right
After a lot of research, I was able to solve my problem
Just go to the manifest file
And make the following line
android:supportsRtl="true"
To
android:supportsRtl="false"

Related

How come you're not suppose to use match_parent in constraint layout?

Everything I've read online says to not use match_parent in the Constraint View for the height and width properties because it can't be used and won't work. I have used a constraint layout in a few projects now where I do use match_parent and it does work. Was there an update that I haven't noticed to where it is now able to be used? If not, how come it is working in my situations while it seems it doesn't work at all for other people?
Example code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f9d1ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/preview"
android:layout_marginLeft="4dp"
android:text="Last Entry:"
android:textSize="12dp"
app:layout_constraintTop_toTopOf="#id/saveButton"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="#id/clearButton"
android:id="#+id/dataText"
android:textSize="16dp"
android:layout_marginLeft="8dp"
android:text=""
android:textStyle="bold"
/>
<Button
android:layout_width="75dp"
android:layout_height="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#+id/clearButton"
android:id="#+id/saveButton"
android:text="Save"
android:textSize="12dp"
android:layout_margin="8dp"
android:background="#drawable/buttonscreen"
android:padding="6dp"/>
<Button
android:layout_width="75dp"
android:layout_height="30dp"
android:gravity="center"
android:padding="6dp"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
android:text="Clear All"
android:id="#+id/clearButton"
android:textSize="12dp"
app:layout_constraintTop_toBottomOf="#+id/saveButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/saveButton"
app:layout_constraintEnd_toEndOf="#id/saveButton"
android:background="#drawable/buttonscreen"/>
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Try this constraints for which view you want to make match parent

Suggestion Strip of Soft Keyboard hides part of the layout

I've tried virtually every solution out there for soft keyboard covering part of the view when pops up, on further investigation I found that it's not the keyboard but the suggestions strip that's covering the layout.
But disabling the suggestion strip from the settings of the keyboard seems the only solution.
I've tried some hacks which add padding at runtime when the keyboard pops up but none seems to work.
This screenshot will explain it better
The below code snippet is from my BottomSheetDialog:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/design_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/feedback_text"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="#drawable/recognition_text_box_border_drawable"
android:gravity="start"
android:hint="#string/manager_recognition_edit_text_hint"
android:importantForAutofill="no"
android:inputType="textMultiLine|textCapSentences"
android:maxLength="200"
android:maxLines="24"
android:overScrollMode="always"
android:padding="8dp"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:textColor="#android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/award_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="#id/feedback_text"
app:layout_constraintEnd_toEndOf="#id/feedback_text"
app:srcCompat="#drawable/trophy_golden" />
<include
android:id="#+id/award_badge_item"
layout="#layout/award_badge_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="#id/feedback_text"
app:layout_constraintStart_toStartOf="#id/feedback_text" />
<LinearLayout
android:id="#+id/buttons_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:orientation="horizontal"
android:weightSum="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/feedback_text">
<Button
android:id="#+id/cancel_recognition"
style="#style/Widget.AppCompat.Button"
android:layout_width="0dp"
android:layout_height="#dimen/medium_button_height"
android:layout_margin="4dp"
android:layout_weight="1"
android:text="#android:string/cancel" />
<Button
android:id="#+id/send_recognition"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_height="#dimen/medium_button_height"
android:layout_margin="4dp"
android:layout_weight="2"
android:text="#string/send_recognition" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
add this line in your manifest activity tag where you are opening keyboard
android:windowSoftInputMode="stateHidden|adjustResize"

Getting the background image to not "squash" when one of the text input's is clicked to bring up the keyboard

So I'm a beginner to coding android and normally I'm able to find my solutions on google but I've had no luck this time. I've made an app with two activities (a login screen that also has a register button that leads to a register screen) and on the initial log in screen, clicking one of the text inputs squashes the background image, to essentially fit it into the smaller space created when the keyboard takes up some of the screen. It's pretty annoying.
Sorry for pasting such a huge block of code but as a beginner, I'm not really sure which part of this code is relevant so I've included the whole xml. Thanks!
Oh, and again - I can't stress enough that I'm a total noob - so could any answers please state crystal clear exactly what code I should be changing/including and in what file, and where abouts in that file?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#drawable/qlogoonwallpaper"
tools:context=".MainActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:layout_marginBottom="48dp">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dropDownWidth="match_parent"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="6"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:background="#color/colorPrimaryDark"
android:text="#string/action_sign_in"
android:textAllCaps="false"
android:textColor="#android:color/background_light"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="-208dp"
android:ems="10"
android:hint="#string/prompt_email"
android:inputType="textEmailAddress" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="225dp"
android:background="#android:color/transparent"
android:text="#string/register_intro"
android:textAllCaps="false"
android:textColor="#android:color/background_light"
android:textSize="18sp"
android:textStyle="bold|italic" />
</RelativeLayout>
Inside the Android Manifest file, try adding the following attribute for your MainActivity :
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustPan">
...
</activity>
that makes the views pan when the soft keyboard appears but the activity's window is not resized. See if that makes any difference. If resizing would work better, instead of the "adjustPan" attribute, you can add "adjustResize". Hopefully one of the two will do the trick for you.

Android Preview Not Translating to Emulator

Now I've already browsed some similar threads, and they helped a bit but I still can't figure this out. I just started Android developing a couple hours ago and I'm following along in this video series, but in the videos the preview matches the emulator exactly. Mine does not. I've attached my xml (however I've been doing this by dragging and dropping on the design tab as that's how the video has been doing it and I know next to nothing about xml coding). The imgur link here has my graphical issue depicted: https://imgur.com/a/WZ6QP0o I would appreciate some advice
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="27dp"
android:layout_marginStart="8dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="8dp"
android:text="Click the button of the larger number. Not hard guy"
app:layout_constraintEnd_toEndOf="#+id/textView2"
app:layout_constraintHorizontal_bias="0.359"
app:layout_constraintStart_toStartOf="#+id/guideline2"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginStart="24dp"
android:text="Bigger Number Game!"
app:layout_constraintLeft_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="13dp"
tools:textSize="30dp" />
<Button
android:id="#+id/left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="212dp"
android:onClick="leftButtonClick"
android:text="0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="211dp"
android:layout_marginEnd="25dp"
android:onClick="rightButtonClick"
android:text="0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/pointsView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="17dp"
android:text="Points: 0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="20dp" />
<android.support.constraint.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="20dp" />
</android.support.constraint.ConstraintLayout>
The tools namespace, which you use in your title TextView, is only used by the design editor. Those attributes are removed at compile-time and so aren't used in the actual app.
You should use android:textSize="30sp" for the text size.
You should set a top constraint for the TextView (app:layout_constraintTop_toTopOf="parent") and then set a top margin (android:layout_marginTop="13dp")

TextView Not centered in app but centered in match_constraint

I've created a simple activity design using ConstraintLayout.
Whenever I try to center a textView, it does it correctly in the blueprints but never does it in the actual app. Not sure if i am doing something wrong or I'm losing my mind.
Here is the image
Here is the XML code
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background_green"
tools:context="nz.co.listcosolutions.StartActivity">
<ImageView
android:id="#+id/imageView4"
android:layout_width="160dp"
android:layout_height="163dp"
android:layout_marginEnd="95dp"
android:layout_marginStart="95dp"
android:layout_marginTop="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/baby_plant" />
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="64dp"
android:text="#string/next"
android:textColor="#color/background_green"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView3" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="20dp"
android:text="Welcome to My App"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView4" />
</android.support.constraint.ConstraintLayout>
Im also using the latest version of ConstraintLayout
compile 'com.android.support.constraint:constraint-layout:1.0.2'
You need to add:
android:gravity="center"
to the TextView.
This is the only certain way to center the text inside a TextView object or one of its subclasses.
The android:textAlignment is not working in all the cases and as reported by this answer that it has problems in lower API levels.

Categories