Why is my EditText not editable? - android

Why is my EditText not editable?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical"
android:textAlignment="center"
android:weightSum="2"
tools:context="com.example.musicvideomaker.ProjectSettingsX"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:text="Project Name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:singleLine="true" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:text="Save" />
</LinearLayout>
I run the app in the emulator and I can't change the EditText. The keyboard doesn't appear when I touch it. I have tried it on multiple emulators.

Your EditText is editable, but your emulator probably doesn't have keyboard support. You will need to edit the AVD to add an option as follows:
From Eclipse, Go to AVD Mananger.
Select the particular AVD and click on Edit
Go to the Hardware section, click on New.
Select the Property Name : Keyboard Support
By default, it is added with a value of 'no'. Just click on the value column and change it to 'yes'.
Click on Edit AVD again.
This will add a property hw.keyboard=yes in config.ini file for the AVD. And it should work fine from there.

I dont think its a code problem. I think its got something to do with the emulator itself. Avds are usually made to use input from your computer's physical keyboard, so try just typing on it, if you dont want to do that.
Go to AVD manager, click on your device, and click on edit.
See this:
Check/uncheck it as per your need.

Related

Android studio different layout on emulator

I just started using android studio and I inserted a button and text field. In preview panel looks ok but when I run the app the layout it's different.
This is the xml code:
<android.support.constraint.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"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context="com.example.alexander.myapplication.MainActivity">
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="119dp"
tools:layout_editor_absoluteY="222dp"
tools:ignore="HardcodedText,MissingConstraints"
android:onClick="buttonClicked"
/>
This is how it looks like
Thank you!
Look at the lines:
tools:layout_editor_absoluteX="119dp"
tools:layout_editor_absoluteY="222dp"
What they say is that you placed the button in an absolute position BUT only in the editor preview.
The button doesn't have real placement values when the app actually running (notice the "editor" prefix in the parameters name).
You need to define actual values in the editor.
Check out this guide on the Android developers site:
Build a Responsive UI with ConstraintLayout
I just solved the problem by setting the layout to RelativeLayout.

Text color is changing in Android Studio but not showing on phone

I have browsed through a few places but can't find anything "exact" to solve my issue. I set code in Android Studio and the display showed my top text as orange and the bottom text as blue...which is what I intended. When I tried running it on my phone, the text color did not show as it does in Android Studio. (Just is gray text on my phone)
This is a simple bit of code as I'm currently learning from Udacity and a couple other places. Any ideas why code would show as working on Android Studio but wouldn't work on the phone? (especially when dealing with something as simple as text color?)
The code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.saoiray.happybirthday.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="I'm awesome! Birth of a developer (^_^)"
android:textColor="#FF5722"
android:textSize="32sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Oh yeah, Stephen is awesome!"
android:textColor="#3F51B5"
android:textSize="32sp" />
<ImageView
android:id="#+id/androidparty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="#drawable/androidparty"
tools:ignore="ContentDescription" />
</RelativeLayout>
I had the same problem, and i disabled the "High contrast fonts" from the Settings-> Display -> Visibility enhancements , of the phone and now the textColor appears like in Virtual Device

Android Studio - Soft keyboard 'Enter' making text disappear

When I'm using my app to enter text into an editview, when I click the Enter button on the soft keyboard the text entered is disappearing. Ideally I would like the app to go to the next edittext box when the user clicks the button as it does on a different form, however the XML is the same for the button so unsure as to why there is a difference
To try getting the enter button move to the next edit text I've tried inputting the following into the XML but had no luck so far
android:imeOpions="actionNext";
XML For Control As Requested
<EditText
android:layout_width="0dp"
android:layout_height="40dp"
android:id="#+id/text_name"
android:layout_weight="1"
android:visibility="invisible"
/>
Comment: Removed Line above as didn't work
I created a basic activity a simple layout ( shown below). When I press enter in the edit text, it goes to the next edit text.
I added the code you mentioned
(android:imeOpions="actionNext";)
but I also had to add:
android:singleLine="true"
EDIT: singleLine is deprecated.
You can simply add
android:inputType="text"
to your editText.
That worked for me. I think the reason that the line was disappearing was because it was being shifted up and out of the bounds of the textview. The EditText thought you wanted to create a new line. That's my guess.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.slipperyslope.aperturelabs.nextfield.NextEditTextActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Example"/>
<!-- This way works!-->
<EditText
android:id="#+id/first_edittext"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="text"
/>
<!-- This way works! But it's deprecated-->
<EditText
android:id="#+id/second_edittext"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:singleLine="true"
/>
<!-- dummy edit text just to transition to. -->
<EditText
android:id="#+id/third_edittext"
android:layout_width="100dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
Let me know if this works or if you are still having issues.

android edit text doesn't accept numric input

I developing android application and this problem I've get stuck on since yesterday and I don't know what is the problem.
the edit text doesn't take numeric input. my XML code
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="#dimen/dp5">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/dp15"
android:orientation="horizontal"
android:weightSum="2">
<EditText
android:id="#+id/home_et_code"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.3"
android:hint="#string/code_number"
android:inputType="number"
android:maxLength="18"
android:maxLines="1" />
<Button
android:id="#+id/home_btn_charge"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:text="#string/charge"
android:textAppearance="?android:attr/textAppearanceButton"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout></LinearLayout>
if I remove android:inputType="number" then it starts working and takes input, but I need the edit text to accept only numeric input.
I didn't handle anything in java yet. so no need to add the java code.
NOTE: it works fine on android > 14, but on Gingerbread devices the problem occurs
what is the problem??
android:digits="1234567890"
try to put this line on your edittext
now it works fine, because I updated android sdk platform I noticed a lot of problems like the edit text input also back button press is not detected in code. but all what I have to do is to close android studio and reopen it then I compile my application. finally it works again!!

no keypad for edittext in android

In my project I am not getting the keypad for EditText but if I type using the keyboard I am able to add the data but in emulator not keypad is visible.
Went to through this post and made changes but no luck.
my XML file
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/button1"
android:focusable="true"
android:focusableInTouchMode="true"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="Brokerage Detail" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button2"
android:layout_alignParentLeft="true"
android:layout_below="#+id/button1" >
</ListView>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="AddStock" />
Please help me in solving this issue
You need to Edit your AVD and set both :
Keyboard Lid Support and Keyboard Support to YES
Then restart your AVD. May be it will work.
See avd image below:-
EDIT : To enable soft keyboard in Genymotion
Go to Settings -> Language & input and open the Default item under Keyboard & Input Methods. There is a Hardware setting that you can toggle on/off. When it is on you use your physical keyboard and when it is off the standard soft keyboard should pop-up whenever a text field gets focus.

Categories

Resources