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"
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!
New Layout editor in Android Studio 2.2 keeps showing this error on views like EditText and Buttons. kindly help.Also, any links that help in onboarding with the new constraint layout would be appreciated.
code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="#+id/activity_main"
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="com.set.email.MainActivity"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">
<TextView
android:text="To:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="7dp"
tools:layout_editor_absoluteY="4dp"
android:id="#+id/textTo"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="24dp"
android:id="#+id/editTo"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
<EditText
android:layout_width="384dp"
android:layout_height="42dp"
android:inputType="textPersonName"
android:ems="10"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="94dp"
android:id="#+id/editSubject"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
<EditText
android:layout_width="384dp"
android:layout_height="273dp"
android:inputType="textPersonName"
android:ems="10"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="179dp"
android:id="#+id/editMessage"
app:layout_constraintLeft_toLeftOf="#+id/activity_main"
tools:layout_constraintLeft_creator="50"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
<Button
android:text="Send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="140dp"
tools:layout_editor_absoluteY="454dp"
android:id="#+id/btnSend"
app:layout_constraintLeft_toLeftOf="#+id/editMessage"
tools:layout_constraintLeft_creator="0"
app:layout_constraintRight_toRightOf="#+id/activity_main"
android:layout_marginEnd="16dp"
tools:layout_constraintRight_creator="0"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
</android.support.constraint.ConstraintLayout>
From Android Studio v3 and up, Infer Constraint was removed from the dropdown.
Use the magic wand icon in the toolbar menu above the design preview; there is the "Infer Constraints" button. Click on this button, this will automatically add some lines in the text field and the red line will be removed.
Constraint layout aims at reducing layout hierarchies and improves performance of layouts(technically, you don't have to make changes for different screen sizes,No overlapping, works like charm on a mobile as well as a tab with the same constraints).Here's how you get rid of the above error when you're using the new layout editor.
Click on the small circle and drag it to the left until the circle turns green,to add a left constraint(give a number, say x dp. Repeat it with the other sides and leave the bottom constraint blank if you have another view below it.
Edit: According to the developers site, Instead of adding constraints to every view as you place them in the layout, you can move each view into the positions you desire, and then click Infer Constraints to automatically create constraints. more here
Just copy this code to all components that you will drag.
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
example:
<TextView
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="To:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="7dp"
tools:layout_editor_absoluteY="4dp"
android:id="#+id/textTo"/>
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
This help me a lot
Go to the Design, right click on your Widget,
Constraint Layout >> Infer Constraints. You can observe that some code has been automatically added to your Text.
Follow these steps:
Right click on designing part > Constraint Layout > Infer Constraints
If Inferring the Constraints still gives you the error, just use this code:
app:layout_constraintBottom_toBottomOf="parent"
You need to drag the EditText from the edge of the layout and not just the other widget. You can also add constraints by just dragging the constraint point that surrounds the widget to the edge of the screen to add constraints as specified.
The modified code will look something similar to this:
app:layout_constraintLeft_toLeftOf="#+id/router_text"
app:layout_constraintTop_toTopOf="#+id/activity_main"
android:layout_marginTop="320dp"
app:layout_constraintBottom_toBottomOf="#+id/activity_main"
android:layout_marginBottom="16dp"
app:layout_constraintVertical_bias="0.29"
Go to the XML layout Text where the widget (button or other View) indicates error, focus the cursor there and press alt+enter and select missing constraints attributes.
for example I have this
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
use RelativeLayout layout like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
Simply switch to the Design View, and locate the concerned widget. Grab the one of the dots on the boundary of the widget and join it to an appropriate edge of the screen (or to a dot on some other widget).
For instance, if the widget is a toolbar, just grab the top-most dot and join it to the top-most edge of the phone screen as shown in the image.
You have to change androidx.constraintlayout.widget.ConstraintLayout to RelativeLayout.
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.
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.