I have a layout with two text input fields, which disappear & re-appear as options change.
However, when I use attribute app:endIconMode="clear_text", these two warnings flood the logs without end, for both of the text fields.
W/View: requestLayout() improperly called by
com.google.android.material.textfield.TextInputEditText{ba3099c
VFED..CL. ......ID 0,0-1244,272 #7f0a00c6 app:id/homeInput} during
layout: running second layout pass
W/View: requestLayout() improperly called by
com.google.android.material.textfield.TextInputEditText{f641714
VFED..CL. ......ID 0,0-1244,224 #7f0a00e6 app:id/lockInput} during
layout: running second layout pass
The text fields that are visible depends on RadioButton selections
Snippet of one of the text field XMLs:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/alt_sub"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="40dp"
android:animateLayoutChanges="true"
app:boxCornerRadiusTopEnd="8dp"
app:boxCornerRadiusTopStart="8dp"
app:boxStrokeColor="#color/colorAccent"
app:endIconMode="clear_text"
app:hintTextColor="#color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/main_sub">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/lockInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_+"
android:fontFamily="#font/opensansregular"
android:inputType="textNoSuggestions" />
</com.google.android.material.textfield.TextInputLayout>
Whenever I call setText() or setHint() in the Activity class, the warning starts to pop up. The warnings only stop when the text field is empty.
I feel that this may be related to the attribute app:endIconMode="clear_text", but I can't find a way to use it without getting these warnings.
I had the same issue with different endIconModes and didn't find any solution on the internet so I opened a defect with google:
https://issuetracker.google.com/issues/132651327
The issue was fixed today and it should work properly in com.google.android.material v1.1.0-alpha07 when it will be released this week.
Related
I am trying to display an end drawable in my textinputlayout. However, the drawable covers the background of the textinputlayout in an unwanted manner (see image Drawable obstructs the background).
The same behaviour occurs when using an outlined style.
Another problem occurs where the suffix behaves the same way (see image Suffix problem).
Furthermore, the error icon is hidden until there is text in the edittext of the textinputlayout (see images No error icon,Error icon).
The error icon also displays the same strange visual behavior.
This is what my textinputlayout looks like:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/locationTVLayout"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hapticFeedbackEnabled="true"
android:hint="Where?"
app:endIconContentDescription="Find my location."
app:endIconDrawable="#drawable/ic_baseline_location_searching_24"
app:endIconMode="custom"
app:endIconTint="#color/colorAccent"
app:errorEnabled="true"
app:startIconDrawable="#drawable/ic_baseline_location_on_24">
<AutoCompleteTextView
android:id="#+id/locationTV"
style="#style/Widget.MaterialComponents.AutoCompleteTextView.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:completionThreshold="1"
android:layout_below="#id/tempInputTV"
android:nextFocusForward="#+id/tempInputTV"
android:selectAllOnFocus="true"
android:singleLine="true"
/>
</com.google.android.material.textfield.TextInputLayout>
My Material gradle reference is :
api 'com.google.android.material:material:1.3.0-alpha02'
Use app:startIconDrawable and app:endIconDrawable instead of android:drawableStart and android:drawableEnd.
Both of these go into your TextInputLayout and not in TextInputEditText.
For more reference, check this out: https://material.io/develop/android/components/text-fields
I have a RecyclerView. I need to set the value of overScrollMode = "never" to remove this animation , but at the same time the fadingEdge option is disabled. Can you help me turn off the animation about which I wrote above, without disabling fadingEdge?
SOLUTION
If you do this in XML, then when you disable OverScrollMode - fading also becomes inaccessible, but if you do it programmatically, everything will work.
recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
recyclerView.setVerticalFadingEdgeEnabled(true);
recyclerView.setFadingEdgeLength(Math.round(30 * Resources.getSystem().getDisplayMetrics().density));
SOLUTION 2
#RakeshKumar proposed an option with XML. In order for fading not to disappear, you must also specify the background for RecyclerView.
android:background="YOUR COLOR"
android:fadingEdgeLength="30dp"
android:requiresFadingEdge="vertical"
android:overScrollMode="never"
You can use this like following:
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:overScrollMode="never"
android:background="#ffffff"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fadingEdgeLength="30dp"
android:requiresFadingEdge="vertical"/>
The target I need to achieve: 2 lines of text and 1 straight line in between should always be on top of Button. So in such a case, setting text in Button's attribute is not applicable according to my knowledge. Therefore I use TextView and View aligning on top of Button to achieve it.
Problem: A strange UI appearance I have come across of Android 5.0+ is that when the Button is enabled, it covers TextView and View even it comes before TextView in RelativeLayout xml file. (according to my knowledge, this means that TextView should on top of Button) The following is my xml code:
<RelativeLayout
android:id="#+id/rl_daily_check_in_button_container"
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_marginBottom="4dp"
android:layout_centerHorizontal="true"
android:layout_above="#+id/textview_check_in_days_in_row">
<Button
android:id="#+id/button_daily_check_in"
android:layout_width="140dp"
android:layout_height="140dp"
android:background="#drawable/daily_checkin_button" />
<TextView
android:id="#+id/textview_check_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="#+id/view_line"
android:layout_marginBottom="4dp"
android:text="#string/title_not_yet_daily_check_in"
android:textColor="#color/text_gray"
android:textStyle="bold"
android:textSize="36sp" />
<View
android:id="#+id/view_line"
android:layout_width="94dp"
android:layout_height="1dp"
android:layout_centerHorizontal="true"
android:layout_above="#+id/textview_check_in_points"
android:layout_marginBottom="6dp"
android:background="#color/text_gray" />
<TextView
android:id="#+id/textview_check_in_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/points_can_get_daily_check_in_placeholder"
android:textColor="#color/text_gray"
android:textSize="14sp" />
</RelativeLayout>
But when the app is in Android 5.0-, say 4.4.2, the UI is exactly what I expect. I have tried to set android:elevation="xxdp" attribute, it success until I set the background of Button programatically. Can anyone explain the reason and how the Andoird 5.0+ render its UI? Many Thanks!
Button on Andoird 5.0+:
Button on Android 5.0-:
From Android Lollipop (5.0), the Button has a default StateListAnimator. It has set the default android:elevation and android:translationZ attributes to the Button. Since the Button has default elevation set to it, it appears above the other Views that doesn't have elevation set (Views that has elevation less than the Button, to be precise). i.e. The Views that has higher elevation set to it will appear above the Views that has lower elevation set.
So that's why, when you changed the Button to ImageView, the problem is solved, because ImageView has no default elevation set.
Issue
I've got an issue with 2 ImageViews on Android.
The first displays a large image. It is inside a RelativeLayout, and is a custom ImageView (com.ortiz.touch). It was displaying well until now.
The second is also inside the RelativeLayout but is a "normal" ImageView. It shows bluetooth state. Displaying it doesn't cause any issue.
However, when I put code that changes the src of the bluetooth indicator programatically, the first image is not displayed anymore ....
Is the problem coming from the custom view not doing its job right ? Am I missing something ?
Code
If I'm not doing this kind of stuff :
bluetoothState.setImageResource(R.drawable.bluetooth_enabled192);
The image is displayed correctly.
Here's the layout I use :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1b1b1b"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<com.ortiz.touch.TouchImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView"
android:layout_gravity="center"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_above="#+id/textView" />
<TextView
android:layout_width="fill_parent"
android:layout_height="32dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/emptyDisplayText"
android:layout_gravity="center_horizontal|bottom"
android:gravity="center_vertical|center_horizontal"
android:textAllCaps="true"
android:elegantTextHeight="false"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="15sp"
android:textColor="#f3f3f3"
android:id="#+id/textView"
android:background="#drawable/rounded_rect"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_margin="10dp" />
<ImageView
android:layout_width="52dp"
android:layout_height="52dp"
android:id="#+id/bluetooth_state"
android:scaleType="centerCrop"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:layout_gravity="top|right"
android:layout_margin="10dp"/>
</RelativeLayout>
Desired Result
What I get is the same screen without the central image (the text and bluetooth indication are displayed correctly)
NB
I'm starting to get quite depressed on that issue. I just want to display 2 images. Thank you.
Edit
I've not mentioned it, but the main image is loaded in background, using an AsyncTask. I've tried to add some View.invalidate() (on top level layout, on image, on bluetooth indication) but it hasn't solved the problem.
In addition to the image appearing on rotation, it also appears when I try to pinch the non-existant image. And trying to reset the zoom (hacky) programatically doesn't work either.
Okay I've found the error.
As I said, I have a AsyncTask (BitmapWorkerTask) that I call to load a Bitmap into an ImageView in background.
It's called like this :
new BitmapWorkerTask(imageView, getApplicationContext()).execute(filename);
Changing getApplicationContext() to MainActivity.this or getContext() solves the issue :/ (However, I still find it's quite magic how it worked fine for so long even if application context != activity context !)
I have the following Textview:
<TextView
android:id="#+id/detailsText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Long text Long text Long text Long text Long text Long text "
android:textAppearance="?android:attr/textAppearanceLarge"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true" />
The text is automatically scrolling from right to left (which is what I'm looking for) but after a configuration change the text restart scrolling from the beginning. I have tried to use android:configChanges="orientation|keyboardHidden|screenSize" and handle the configuration change in my code but this is not working. I also find out that this technique is not advised anymore, and tried to use Fragments instead, but nothing is working. I tried also to find out which value scrollHorizontally is modifying to do it's scrolling so I can try to save and restore it, but I never find it (textview.getScrollX() always stay at 0 for example).
I also noticed that this "scrolling restart" also happen when I use the textview.setVisibility(View.GONE); and textview.setVisibility(View.VISIBLE); methods.
Thanks for the help.