I have an editText field in my app and the keyboard pops up when I focus the text field on lower APIs than 10. For some reson, the keyboard doesnt show when the editText is focused in APIs higher than 10. Also in API higher than 10, in the logcat it says eglSurfaceAttribute not implemented whenever I focus the EditText field. Thanks in advance.
One way to bring up the soft keyboard when EditText is focused is to add <requestFocus/> to the EditText in the XML layout.
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<requestFocus />
</EditText>
Let me know if this helps.
Just put this line on your onCreate()
editText.requestFocus();
Related
I am trying to create a Sign Up page in the latest Android Studio Arctic. So I am trying to customize and style the buttons using Button Class, but no observable changes were made, until I used AppCompatButton, and all the styles and customization for the button were implemented. I want an elaboration between the two Views and why I could not make the changes using Button Class. Thanks.
These are the codes for AppCompatButton and Button
<androidx.appcompat.widget.AppCompatButton
android:id="#+id/sign_up_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/button_border_signin"
android:elevation="0dp"
android:text="Sign Up"
android:textColor="#e0e0e0e0"
android:textStyle="bold" />
Button
<Button
android:id="#+id/sign_up_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#drawable/button_border_signin"
android:elevation="0dp"
android:text="Sign Up"
android:textColor="#e0e0e0e0"
android:textStyle="bold" />
Possible Reason
You might be using some features that are not compatible for older versions in your background drawable file.
Difference between Button and AppCompatButton
An AppCompatButton is simply a Button which supports compatible features on older versions of the platform, including:
Allows dynamic tint of its background via the background tint methods in ViewCompat.
Allows setting of the background tint using R.attr.backgroundTint and R.attr.backgroundTintMode.
Allows setting of the font family using R.attr.fontFamily
This will automatically be used when you use Button in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.
Source: AppCompatButton
I am new to Android development and need some pointers around the input. I am familiar with the use of Android and I would like to know how to complete general actions around the keyboard.
I know how to set it to things such as phone, email, decimal, and so on.
But how do you change it to move to the next field or fire an action?
Thank you for your insights.
You need to add this attribute in editext xml android:imeOptions="actionDone"
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:inputType="text"/>
I have 2 edittext fields in an app.
Depending on which radio button is selected one of these fields is disabled.
The problem is that when the top field is enabled the user types in a double and then there is no option to be "done" with the keyboard because it still considers that the next field needs to be filled in even though it's disabled.
How can I change this?
Include the imeOptions and singleLine attributes in your EditText.
<EditText
...
android:imeOptions="actionDone"
android:singleLine="true" />
I have an edittext enclosed within a textinputlayout from the support library and I'm finding it impossible to make the hint appear in the center of the field. I've tried all the usual tricks to be found in other stackoverflow discussions, as you can see from the code sample, but the hint still stubbornly appears on the left of the edittext. How can I solve this?
Please don't suggest using paddingLeft or paddingStart to do this - I want something that's going to work cleanly across different devices so it has to be a straight solution rather than a workaround.
Just to be clear: If I remove the textinputlayout then the hint is properly centered. It's the textinputlayout that's causing the problem here.
<android.support.design.widget.TextInputLayout
android:id="#+id/someId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:layout_marginRight="30dp"
android:layout_marginEnd="30dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:ellipsize="start"
android:maxLines="1"
android:inputType="textPersonName"
>
<EditText
android:id="#+id/someId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="#string/somehint"
android:textColorHint="#color/somecolor"
android:textSize="20sp"
android:textColor="#android:color/black"
android:background="#android:color/white"
android:cursorVisible="true"
android:textCursorDrawable="#null"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:inputType="textPersonName"
android:maxLines="1"
android:ellipsize="start"
/>
</android.support.design.widget.TextInputLayout>
Using the latest version of the support library:
compile 'com.android.support:design:22.2.1'
Edit - things I've tried to resolve this:
1) replacing Edittext with android.support.v7.widget.AppCompatEditText - doesn't work
2) using app:hintTextAppearance="#style/TextAppearance.AppCompat" inside the textinputlayout - doesn't work
3) Instead of defining the hint in the edittext, setting the hint programmatically using textinputlayout.sethint inside the activity - doesn't work: the hint appears on the left.
4) Setting the hint on the edittext in onActivityCreated. This appeared to work initially, but I discovered that although the hint appears centered the functionality of inputtextlayout becomes broken and clicking on the edittext no longer performs the hint animation.
To center the hint text in your EditText just add the following two attributes in your EditText. This will do the trick.
android:ellipsize="start"
android:gravity="center_horizontal"
There doesn't seem to be a way to do this (at least not that I can find). As a workaround I tried using the MaterialEdittext 3rd party library - also not ideal since although the small animated hint is centered, it appears inside the text box instead of outside it:
https://github.com/rengwuxian/MaterialEditText
How would I make an multi-line EditText with a vertical scroll bar go down to a certain spot? I want to do this inside of the Java code, and I'd prefer to do it with an EditText, but I'd be willing to use a ScrollView if I need to.
The EditText XML:
<EditText
android:id="#+id/theTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textAutoCorrect|textMultiLine"
android:scrollbars="vertical"
android:width="0dp" >
You can try using scrollTo api from the view.