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.
Related
When i build my application in android studio and test it on my phone, the edit text doesn't behave like a text editor and creates a popup input field above the keyboard and waits for you to press done. What I want to achieve is to behave like a text editor and get direct input from the keyboard without pressing done every time you want to add something.
I have tried everything in terms of xml attributes. I even searched how other text editor apps achieve the direct input, but with no avail, the popup field that gets the input and waits for you to press done didn't disappear. Here is my xml code for the edit text:
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/code_edit_text"
android:scrollbars="vertical"
android:inputType="textMultiLine"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
android:lines="16"
android:gravity="top|left"
android:maxLines="10000"
android:singleLine="false"/>
I think its better to try after removing
android:background="#drawable/code_edit_text"
android:scrollbars="vertical"
android:overScrollMode="always"
android:scrollbarStyle="insideInset"
these lines
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.
I have a TextView in my android app that I want to display all the text on a single line. Right now, it is displayed like this:
this is som
e text
When I set setSingleLine(), I get this:
this is som e text
(notice the space within some)
When I use setMaxLines(1), I get this:
this is som
What I want is this:
this is some text
How can I force the text to display fully on a single line?
You can try this on your textview's xml:
android:maxLines="1"
You can make scroll text using following code if you want.
<TextView
android:id="#+id/txtBigLongTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold"
tools:text="long text goes here......................"/>
The answers above provide a solution to my issue.
The problem was the previous programmer had implemented logic which automatically started a new line after 20 characters.'
Thanks for your help everyone!
I'm working on an Android App which has a few (Next, Back, ... etc) Buttons which are all round and transparent and I use ImageButton for those Buttons, however the problem is there is always a white border around the Button (I use black background so it is very ugly) and the button never appears to be round is appears as some sort of a square-ish shape.
Here is what I tried so far :
Setting the background of the ImageButton in the activity_mypage.xml file to
android:background="#android:color/transparent"
and to
android:background="?android:selectableItemBackground"
and to
android:background="?android:selectableItemBackgroundBorderless"
even to
android:background="#null"
but nothing seems to work on the .xml side.
and I tried the following on the MyPage.java file :
myBtn.setBackgroundResource(0);
and also
myBtn.setBackground(null);
Nothing seems to work anything I do keeps resulting the same (although it removes a gray border from around the Button but none of them makes the Button completely transparent)
This is a screenshot of the button before applying any of above :
And this is a screenshot of the same Button after applying any of those attributes (doesn't really matter if I applied it only to the xml or only to the java file or to both because all results are the same):
This is my xml code for one of my Buttons in xml :
<ImageButton
android:id="#+id/my_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="26dp"
android:layout_marginEnd="37dp"
android:layout_marginRight="37dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:srcCompat="#mipmap/my_btn"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintRight_creator="1"
android:background="#android:color/transparent"
/>
And here is the code for it in the .java file :
ImageButton myBtn= (ImageButton) findViewById(R.id.my_btn);
myBtn.setBackground(null);
myBtn.setBackgroundResource(0);
I'm really lost at this every result I found for this query has suggested one of the above methods but none of these seems to work for me..
Just change
android:background="#android:color/transparent"
to
android:background="#null"
Try with this
android:src="#mipmap/yourimage"
instead of
app:srcCompat="#mipmap/my_btn"
add this to your button
android:background="#drawable/template"
and create a file name it template in your drawable folder
and add this code to it
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="#drawable/btn2imagePressed"></item>
<item android:drawable="#drawable/btn1imageNotPressed"></item> </selector>
You can use ImageView instead of ImageButton, so background issue will not occur
<ImageView
android:id="#+id/my_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="26dp"
android:layout_marginEnd="37dp"
android:layout_marginRight="37dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:src="#mipmap/my_btn"
/>
So after reading some of the posted answers and playing around with the suggestions in my code I noticed that the icon was incorrectly loaded into my mipmap directory instead of drawables and that is because when I imported the icons I selected New -> Image Asset instead of Vector Asset which caused my 'icon' to lose its transparency ...
Thanks to everyone for their replies and answers.
I am having some problems to underline an EditText in AndroidStudio.
This is what I am looking for (this is just a photo, not my real text):
But I do not really know any property to do that.
My code right now is really simple. Just the "normal" one:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_margin="16dp"
android:id="#+id/tx_titulo"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="#string/pt_titulo"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:allowUndo="true"
/>
I do not want to underline just the text (in this case "TÃtulo"), but the whole PlainText
Does anybody know it?
Greets.
It is default, but try to check your styles. Maybe there is a style that will override the style in the whole application. If there is, just remove it
To do this programatically, you could find an answer in this post.
To set the underline color:
editText.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_IN);
To remove the underline color:
editText.getBackground().clearColorFilter();
To do it from the XML, you could add background property to do the same thing in your layout.xml with any drawable resource as a background by adding:
android:background="#drawable/mydrawable"
If you have a couple of EditText with the same style configuration, to avoid setting the attribute to each EditText, you could override EditText's default attributes, defining a custom style like it is done here.