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.
Related
I have a button with centralized icon+text, and I need to change the app:icon and android:text properties when some event occurred. I know that there is setText() method to change the text, but is there a way to change the icon?
XML:
<Button
android:id="#+id/bottom_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginHorizontal="#dimen/default_margin"
android:layout_marginVertical="#dimen/bottom_bar_content_vertical_margin"
android:backgroundTint="#color/light_green"
android:text="#string/next"
android:textAllCaps="false"
app:icon="#drawable/ic_baseline_next_plan_24"
app:iconGravity="textStart" />
This is a function that is called after appropriate event, and I need to change icon in that function. icon and text are ids of desirable drawable and string:
private void setBottomButton(int icon, int text) {
button.setText(getString(text));
}
You can use the methods:
setIcon
setIconResource
Example:
button.setIcon(drawable)
button.setIconResource(iconId)
Here the doc.
If you check the docs, you'll see the code equivalent for each XML attribute.
Check this link : enter link description here
Searching for drawableLeft shows:
android:drawableLeft:
setCompoundDrawablesWithIntrinsicBounds(Drawable,Drawable,Drawable,Drawable)
I want show image in ImageView, but don't show it. I use XML code and Java code but don't show. show in simulator but in real devices don't show. tested on LG G2, HTC One X, Samsung Galaxy S3.
my xml code :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:background="#drawable/show_sms_header" />
my java code :
Dialog_Header_Img = (ImageView) findViewById(R.id.sms_dialog_header);
Dialog_Header_Img.setImageResource(R.drawable.show_sms_header);
I used to be separated from each.
Please tell me the solution
First of all you should set image in xml by code:
android:src="#drawable/show_sms_header"
not by android:background, well you can set background to color or other image but your main image you should set by android:src
If you changing something about your image, leave first line in your code that you show, and delete second, if setting image is only thing you set, then you can delete both, because you set source of image in xml.
The "src" attribute should be set to your drawable if you want it to be "centerCrop" correctly.
Check this out :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/show_sms_header" />
Make sure that your file, called "show_sms_header", is in your drawable ( /res/drawable) directory.
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" />
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())
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".