I want EditText not to extend IME when it is focused on Android Wear.
I read and implemented in the same way as the following thread:
Prevent EditText from automatically focusing
However, IME appears.
Is it impossible to hide IME for an EditText on Android Wear?
I tried 3 methods:
Added the following code in the onCreate() method:
{getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);}
Added the following code in the activity tag in AndroidManifest.xml
android:windowSoftInputMode="stateAlwaysHidden"
Added the following code in rect_activity_main.xml
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#android:color/transparent"
android:focusable="true" android:focusableInTouchMode="true"/>
None of them worked.
Best regards, gellpro
Check Show the Input Method On Demand. It's noted that the system hides the input method when the user finishes the task in the test field or the user can hide it with a system control. With this, try to specify how your UI should respond. It's mentioned that,
To declare your preferred treatment in an activity, use the android:windowSoftInputMode attribute in your manifest's element with one of the "adjust" values.
Then, to implement hiding IME, try using InputMethodManager with constant set to RESULT_UNCHANGED_HIDDEN. This will flag for the ResultReceiver result code from showSoftInput(View, int, ResultReceiver) and hideSoftInputFromWindow(IBinder, int, ResultReceiver): the state of the soft input window was unchanged and remains hidden.
Hope that helps.
Related
How to Highlight text in android TextView like this?
& also how to show a custom dialogue on text selection?
I Have Tried with TextView default property
android:enabled="true"
android:textIsSelectable="true"
android:focusable="true"
android:longClickable="true"
But By Using this it only show default share and copy option from android.
You can set the hilight by calling setSelection on the TextView. As for the dialog- you can add to it, but you can't remove from it. The way to add to it is to create an Activity with an intent filter that makes it catch the PROCESS_TEXT action. That will automatically make Android add your app to the copy paste bar with the name of your app, and allow users to click on it to perform whatever transformation you wish.
Please note that this will occur in every app, not just your own. I don't know of a way to make it specific to your app.
So for example the "Tweet" option on your bar there is because you have twitter installed. Delete it and the option would disappear. There's no other way, other than to totally turn off that menu and build your own version.
Please Read My Question Carefully
I am learning Activity LifeCycle. I only have one EditText and a TextView in my XML layout With certain id. When I rotate the screen, nothing seems to change because Rotation doesn't affect EditText. But when I remove the id of EditText in XML and rotated the screen, The Rotation Starts affecting and the text in the editText removed due to rotation. I am confused about the relation of EditText with its Id.
I tried to explain the problem below in columns:
Explanation of below Column names
Having Id: Does EditText has id?
Rotation : Phone has Rotated or not
EditText : What happen to EditText After Rotation.
.
Having Id----------------Rotation---------------EditText
Yes Rotated Does not change
No Rotated Yes, Text Removed from editText
MainActivity.java is empty and main_activity.xml code is below:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter here"
android:inputType="textPersonName"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.371" />
<TextView
android:id="#+id/textView2"
android:layout_width="85dp"
android:layout_height="25dp"
android:layout_marginTop="88dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Sorry for using bad English and High-resolution pictures as I have no other ways. Best Regards
One of the most important aspects in Android programming is to handle the configuration changes and most common of them is orientation changes. Although it is not recommended to handle configuration changes yourself, due to the hidden complexity of handling the configuration changes, there are cases where we might need to handle manually.
If you need to save the state, the common approach is to implement onSaveInstanceState to store & restore the values which are passed as Bundle.
Coming back to your question:
Relation of EditText with its Id in Android Studio?
When it comes to saving state of View Android OS automatically calls the View.onSaveInstanceState method on each of the views in your view hierarchy as long as you call through to the super method in onSaveInstanceState. In order to restore the data, it uses android:id attribute key for that particular View’s state.So for your case, when you don't provide the id for EditText, the View's state won't be stored due to missing key.
Hope this clarifies the relationship of id to EditText
When you rotate screen on android all activities and fragments in your application are destroyed and then recreated. Android does this so that your application can reload resources based on the new configuration.
When the system destroys the activity (e.g. when the screen rotates) then although the actual Activity instance is gone, the system remembers that it existed. The system creates a new instance of that activity using a set of saved data that describes the state of the activity when it was destroyed.
when your assign an id to a view it seems that android keeps track of that view. Hence it remembers it's state.
Okay when you rotate the device this is considered as a configuration change, so the system recreates the activity and data is lost.
One way to avoid this is go to the manifest and for your specific activity add this
android:configChanges="orientation|screenSize"
here:
<activity
android:name=".YourActivityName"
android:configChanges="orientation|screenSize"
....
...
This makes the system ignore the rotation of device.
In manifest of your app, add this line to activity tag:
android:configChanges="keyboardHidden|orientation|screenSize"
The reason for this is due to Android basically destroying the activity and creating it again every time you rotate the device. This is mainly to allow for different layouts based on portrait/landscape mode.
When you use id for your component, data will be assigned to its id, but when it hasn't id, it will be recreated and data will be disappeared after rotation.
See these questions and read their good answers, I don't copy and paste them:
1- TextView's text disappearing when device rotated
2- Handle screen rotation without losing data - Android
EditText is a focused view, so in PhoneWindow, it's state will be saved automatically in saveHierarchyState() method. Only EditText with id is going to save text.
Okay, the relation of one specific EditText item to its id is: "one to one" or "one to N". One EditText item in one layout.xml has one id, if you've configured it in the layout.xml. If you've defined more than one layout.xml's and the very same EditText item (having the same id) in more than one layout.xml's, then EditText has a "one to N" relation.
I am developing an android app as an educational project. I have created a GridView object, which uses a custom GridAdapter. The grid, as default, loads a set of placeholder images. I want the user to be able to replace those placeholder images with either their own image, some text, or a link to a youtube video.
I can't find any info on whether this is feasible. I specify an Imageview in my XML file, so I don't know how I could change this at run time? I wondered if I should create a TextView object in the XML, and layer them, and then create a method that brings one to the front? Any advice at all would be very much appreciated. It would be great to know if it's doable or not.....
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_centerInParent="true"
/>
My suggestion is define TextView etc. in xml with gone visibility. When user has some actions get visible them and set visibility gone of ImageView.
Set the visibilities of the container based on user input... What ever user chooses make tat container visible and other two as Gone... This would work
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 used the XML syntax to create a PreferenceActivity with a PreferenceScreen. I added an EditTextPreference and noticed that this renders as a dialog. Is there a way to make the EditText in-place i.e., the text field is displayed right in the PreferenceScreen instead of popping up as a dialog?
In case anyone comes across the same problem, this cannot be accomplished with the built-in Preference classes, but you can subclass Preference, and override getView() to return a ViewGroup containing an in-line EditText (or simply the EditText itself).
You could probably achieve this by providing the android:layout attribute in the XML too (although I haven't tried this).
EDIT:
I tried the android:layout approach above, and it works pretty well.
add android:layout="#layout/your_loyout".
where your_layout.xml is like
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />