EditText.setError() on single line - java

I have a question about EditText.setError().
I have an EditText :
<TextView android:id="#+id/sc_num"
style="#style/textLabel"
android:text="#string/scnum"
android:layout_below="#+id/creditCard"/>
<EditText android:id="#+id/credit"
android:background="#android:drawable/editbox_background"
android:layout_below="#+id/sc_num"
android:layout_alignRight="#+id/state"/>
I want to display the error message "please enter a valid security code"
using the setError() method.
When I run the app I'm getting an error displayed in multiple lines as shown in the picture
What would I do to display this error in single line?

Try android:scrollHorizontally="true".
EDIT:
Use android:SingleLine="true".

Related

No speakable text present at Android Studio

When adding a field for entering a number(Number widget), the error "No speakable text present at Android Studio" takes off
enter image description here
content_main.xml: enter image description here
activity_main.xml: enter image description here
The problem is you are missing content labeling for the view, you should add content description so the user could simply understand what data he should enter into the view
for example, if you want the user to enter the number of cookies he wants you should add a content description as seen below:
android:contentDescription="Enter How Much Cookies You Want"
You should also add an android:hint so the user would have it in front of them an example of the data you want inputted for example:
android:hint="e.g 5"
So your views XML code should look as follows
<EditText
android:id="#+id/editTextNumber2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:minHeight="48dp"
android:contentDescription="Enter How Much Cookies You Want"
android:hint="e.g 8" />
The solution is simple you just need to add the text into the hint part.
search hint in search-bar ant type something in hint block.
and hit Enter.enter image description here
The problem is missing constraints. Any view you add in Constraint layout, you must set the margins otherwise you will get those errors and even if your app managed to run, your edit text will not be place properly.
Add this to your editText;
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Let me know if it worked.
Remember you can twick this to your desired position.

Android Studio throws "image not found" exception

I am facing a problem. When I was set an image in my image button then it correctly shown in design view but when I run the program then my app unfortunately stop and shows the error "resource not found" exception.
How can I fix this problem?
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/login_button"
android:textStyle="bold"
android:drawableLeft="#drawable/enter"
android:drawableStart="#drawable/enter" />
My image name is enter.png.
I assume you are referring this button in your code, but it doesn't have an id to refer to. You need to android:id to your xml here then refer to it in your code.

Why is TextInputEditText producing this error?

I've been trying to change the fontfamily of my application to advent pro. The problem is only my textinputedittext produces this error
java.lang.RuntimeException: Font not found C:\Users\owner\AndroidStudioProjects\Application\app\src\main\res\font\advent_pro_medium.ttf
Everything works fine on buttons and textviews. I've also tried using edittext, it does not produce this error but the fontfamily doesn't get applied. I have my font in the exact same directory that the error states, so why is textinputedittext producing this error? Below is the code of my textinputedittext..
<android.support.design.widget.TextInputEditText
android:id="#+id/etJoinCode"
android:layout_width="match_parent"
android:layout_height="35dp"
android:fontFamily="#font/advent_pro"
android:hint="#string/join_code"
android:textColor="#ffff"
android:textColorHint="#ffff"
android:textSize="14sp" />
Remove android:fontFamily="#font/advent_pro" in your xml code .
1.create a new fonts directory in the assets directory and put the advent_pro_medium.ttf font file here.
2.You can change to this .
Typeface tf = Typeface.createFromAsset(v.getContext().getAssets(), "fonts/advent_pro_medium.ttf");
etJoinCode.setTypeface(tf);

How to remove google plus button message?

I'm trying to add goople plus 1 button in my app and when the user clicks and recommends the link, this message shows up "+1 Recommned this on Google" .How can i remove this message and display just a ballon with the number of recommendation of the link?
<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="#+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
plus:size="standard"
plus:annotation="inline" />
http://developer.android.com/reference/com/google/android/gms/plus/PlusOneButton.html#ANNOTATION_NONE Says...
"Sets the annotation to display next to the +1 button. This can also
be set using the attribute plus:annotation="none|bubble|inline". "
Therefore try:
<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="#+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
plus:size="standard"
plus:annotation="none" />

ellipsize disable initial text

I have a strange behavior with the use of singleLine=true and ellipsize=start with a Button.
First of all, the declaration of my button :
<Button
android:id="#+id/enterDeparture"
android:layout_width="175dp"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:background="#drawable/field_button"
android:text="#string/research_enterDeparture"
android:textColor="#drawable/field_button_textcolor"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:ellipsize="start"
android:singleLine="true" />
With this declaration, no text is displayed inside the button. But if I write Log.d(TAG, "the text is : " + findViewById(R.id.enterDeparture));, the LogCat gives me the correct value...
I tried to set the text programatically, either in the onCreateView() and in the onResume() methods : same behavior. But if I set the text really later of if I put an AlertDialog over my screen, the content come back immediatly...
To finish, if I remove the two lines android:ellipsize="start" and android:singleLine="true", everything is normal : my text is displayed in the first time.
EDIT
I tried to remove the singleLine=true line : the initial content is actually displayed but the ellipsize behavior doesn't work anymore...
So I tried with maxLines=1 : the initial content is displayed, but the "..." are not shown anymore (the content is just truncated).
Try changing the height value:
android:layout_height="wrap_content"
You could be elipsising your text to ... and because the button padding it could be being hidden.
Also you want to try this instead:
Log.d(TAG, "the text is : " + ((Button)findViewById(R.id.enterDeparture)).getText())

Categories