TextInputLayout in listview - android

When I use Material Design Support TextInputLayout in a Classic Layout, I have no problem, I get the hint animation.
But when I use it inside a listview, I lose this, and it behaves like a classical Edittext.
Why???
Here is my code ( one cell xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/ll_row"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/til_valor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="test2"
android:imeOptions="actionNext">
<EditText
android:id="#+id/valor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="test"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<ImageButton
android:id="#+id/cambutton"
android:layout_width="50dp"
android:layout_height="match_parent"
android:background="#drawable/button_azul_states"
android:contentDescription="Tomar foto"
android:gravity="center"
android:src="#drawable/ic_action_device_access_camera" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Initially, I had it with LinearLayout, I tried to use NestedScrollView, without success...

Try removing both hint in layout and call setHint only on TextInputLayout instance from code
EDIT:
I realized that my answer is wrong. My case is different because I use a RecyclerView, I've tried with the ListView and the animated hint just won't work...
I suggest you to convert to RecyclerView, it's easy and solves the issue

Related

How to put ProgressBar inside of EditText and keep the bar right in it?

I want to have a ProgressBar inside of an EditText, but I want it to be right inside it and, preferably, in the center of the EditText. All the solutions I've come across so far do not really allow the bar to be inside of the borders. Also, I'm looking for as clean solution as possible, not just putting over 9000 constraints in ConstraintLayout.
It should look like this (picture is taken from android progressbar inside edittext):
But the actual result is either this:
or this (if I use smaller style for the bar):
My code is:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<EditText
android:id="#+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"/>
</FrameLayout>
Of course, I could just put some hardcoded values for height, but it's definitely a bad fix of the problem. Also, if I change the style of the bar to the smaller one, it's not a fix, since I want to have some control over it (and it doesn't look perfect, either). I'm planning to add something like error and success icons also, so the solution that fulfills this requirement is extremely welcome! So, if you have any clue about how to put it properly inside of the input field, I'll be grateful.
Thanks in advance, guys!
You can try:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<EditText
android:id="#+id/edit_text"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ProgressBar
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
You can achive like this, Whenever you want to position children inside a layout FrameLayout is not a good layout to use. consider using RelativeLayout or better ConstraintLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#null"
android:hint="Phone number goes here" />
<ProgressBar
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:padding="5dp" />
</RelativeLayout>
Happy coding!!

TextView is gone and Button is visible

Textview items are not visible. The Button below them is.
Tried changing the LinearLayout with RelativeLayout, changed the match_parent and content with 0dp. None of them worked. Only the button shows in the right spot as though the TextViews are there but invisible. These views are called in the onCreate() of the Activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".EnterData">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvDateIn"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
tools:text="Date"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvDescIn"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
tools:text="Description"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvAmountIn"
tools:text="California"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
android:textColor="#000"
android:textSize="17sp"/>
<Button
android:id="#+id/btnSendData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Send Data"/>
</LinearLayout>
You try to use android:text instead of tools:text. tools:textonly visible in the Android Studio.
Or you should use yourTextView.setText("yourText") if you are using tools:text.
Instead of using tool:text in xml use android:text="abc" in textView.
As tool:text is used for android studio layout preview . It does not show text when you run your application .
While android:text is used to set text to textview, button etc.
Yep, it was all working and just placing android:text showed it.
Thank you very much.

Elevation above 2dp causes buttons to disappear

In my code below, I have a white view with an elevation of 8dp. The blue button has an elevation of 10dp so in theory it should show. However, it doesn't. It only shows the part in which it is not directly over the white view. I know it's something to with the elevation however I do not know exactly what. I have sussed out that it's fine when the white view is =<2, but as soon as I set it higher, the problem occurs.
Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="#dimen/login_background"
android:background="#color/colorPrimary" />
<View
android:id="#+id/view"
android:layout_width="#dimen/login_container_width"
android:layout_height="#dimen/login_container_height"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/login_container_margin_top"
android:background="#drawable/login_container"
android:elevation="8dp">
</View>
<Button
android:id="#+id/button"
android:layout_width="190dp"
android:layout_height="50dp"
android:layout_marginBottom="52dp"
android:background="#drawable/login_button"
android:elevation="10dp"
android:text="LOGIN"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</LinearLayout>
The following reflects this Stack Overflow question and the accepted answer.
Let's consider what you start off with. I don't have access to all your dimensions, etc. to make the following look exactly like your example but the basis is there. Below is the base layout. You can see that the button lies beneath the view even though the view has an elevation of 8dp and the button has an elevation of 10dp.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark">
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="175dp"
android:layout_alignBottom="#+id/button"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_margin="30dp"
android:background="#android:color/white"
android:elevation="8dp">
</View>
<Button
android:id="#+id/button"
android:layout_width="190dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="52dp"
android:background="#mipmap/ic_launcher"
android:elevation="10dp"
android:text="LOGIN"
android:textColor="#color/white"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
So, why is this? It is because android:elevation="10dp" in the XML for the button isn't really defining the elevation. Instead, the button's elevation is controlled by a "StateListAnimator" that controls the android:elevation and android:translationZ properties." (See accepted answer to above-referenced question.)
If you don't really care for what the StateListAnimator is doing for your layout, you can simply eliminate it by adding android:stateListAnimator="#null" to the XML for the button. Here is what the layout looks like after adding this code. (Please note that the designer may not show the changes immediately; Android Studio 3.0 Beta 6 didn't). So, you may need to refresh the layout to see the changes.
As you can see, the button is now above the view as we expect.
If you do care what StateListAnimator does for you, you will need to define your own and enter its name instead of #null in the XML statement changed above. The answer I reference above has the StateListAnimator that Android presumably uses, so you can take that as a basis and change the elevation to what you prefer. I haven't tried this, but it should work.

cant type in an EditText android

I have this xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/horizontalPadding"
android:paddingRight="#dimen/horizontalPadding"
android:paddingTop="#dimen/verticalPadding"
android:paddingBottom="#dimen/verticalPadding">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="#dimen/padding" >
<TextView
android:text="#string/training_exercise_set_weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/training_exercise_set_weight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:ems="10" />
</LinearLayout>
</LinearLayout>
When my app is running the keyboard is visible and clickable, but the value of editText doesn't change. how can i resolve it?
If someone is interesed, i resolved using the EditText.requestFocus()
Try to replace android:ems="10" with android:maxEms="10" or android:maxLength="10", I'm not sure, what you want to achieve with this parameter
Hope, this will solve you issue
android:ems="10" is all about width of the view, however you are overriding this setting by layout_width property setting to match_parent.
It looks like you would want two EditTexts to be stretch equally and fill that LinearLayout, so here you wouldn't need ems at all. You would need maxLength instead.
Also note that to stretch those EditTexts you should set their widths to 0dp and set their weight to 1 (or something else. They should be equal).
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="#dimen/padding" >
<TextView
android:text="#string/training_exercise_set_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/training_exercise_set_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:maxLength="10" />
</LinearLayout>
For me, the problem was, I didn't let my PopupWindow be focused. Then I found out that my PopupWindow focusable was by default set to false. So, I try to add 1 new parameter that explicitly tells the PopupWindow is focusable. You can see it in my screenshot below. Previously I didn't pass the false value, only the first three values.
Now, I can type anything in the EditText. This one took a whole day to be resolved. 🤣

TextView not wrapping to multiline

I have a TextView inside a LinearLayout which displays only a part of its text without wrapping to a newline and cannot understand why. It doesn't even show the ellipsis somewhere.
The TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/import_progress_text"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="end"
style="#style/TxtDefault" />
i also tried layout_weight=0 along with layout_height=0 but still no luck. All the siblings inside the LinearLayout have layout_height=wrap_content set.
EDIT
Okay apparently it works when a fixed width is set, but neither with fill_parent nor with match_parent. Is this the expected behaviour?
Per Request the whole layout
Note that inside the FrameLayout is another invisible one, which is rather long
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
style="#style/ContentBody"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/progress"
android:layout_gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/import_progress_title"
style="#style/TxtTitle" />
<TextView
android:layout_width="410dp"
android:layout_height="wrap_content"
android:text="#string/import_progress_text"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="end"
style="#style/TxtDefault" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="410dp"
android:layout_height="wrap_content"
android:id="#+id/progress_bar_view"
android:progress="2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/import_progress_start"
android:id="#+id/progress_text_view"
style="#style/TxtSecondary" />
</LinearLayout>
</FrameLayout>
if you want to always show text in n lines, just add android:lines="n",
or if it's not work, try to use for your TextView ->
android:textAppearance="?android:attr/textAppearanceLarge"
hope that will help.
The code snippet is wrapping to multiline perfectly. There might be some problem with the IDE, which is not previewing properly. Test on a real device.

Categories

Resources