Uppercase getting stuck on for Android EditText control
I have a layout on which I am setting the input type of an EditText control as android:inputType="textCapCharacters". Works fine on this control, but then sticks on, even carrying the uppercase attribute to other applications.
This seems to be the case on a 2.1 Hero and a 2.3 Wildfire.
Any suggestions as to how I can unstick it, or set the keyboard back to a default mode?
Thank you
Here is a code snippet that exhibits the stuck uppercase behavior. I can't imagine that I am the only person that has ever had this problem.
Click into Address Line 1 and capitalised words works fine. On focusing Postcode the keyboard correctly switches to uppercase, but stays stuck in uppercase, no matter what other control you focus on, (e.g. clicking back into Address Line 1) even if you go to another app.
It should be noted that the code seems to work as expected in the emulator and it is only on the physical devices that it locks in uppercase.
I now know that on the Hero, at least, the problem only exists on th开发者_StackOverflow社区e stock keyboard. When using the swiftkey keyboard, all seems well.
I have posted this question on two other forums with no response, but Stackoverflow seems to be the best recommendation for this type of query, but after 8 days I have had no suggestions as to what I could try here either. If more information, different tags, or posting elsewhere would be a better option for me, I would be happy to hear those suggestions also.
Full and complete code exhibiting the error is included below.
Any suggestions, anybody?
import android.app.Activity;
import android.os.Bundle;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<TableLayout android:layout_width="fill_parent" android:id="@+id/tableLayout1"
android:layout_height="fill_parent" android:layout_margin="5dp"
android:stretchColumns="1">
<TableRow>
<EditText android:textSize="17sp" android:layout_height="39dp"
android:layout_width="fill_parent" android:id="@+id/address"
android:hint="Address Line 1" android:layout_span="3"
android:inputType="textCapWords"></EditText>
</TableRow>
<TableRow>
<EditText android:inputType="textCapCharacters"
android:textSize="17sp" android:id="@+id/postcode"
android:layout_height="39dp" android:hint="Postcode"
android:layout_weight="1" android:layout_width="0dip"></EditText>
<CheckBox android:text="Check Me"
android:layout_height="39dp" android:id="@+id/checkme"
android:textSize="12sp" android:layout_weight="1"
android:layout_span="2" android:layout_width="0dip"
android:layout_gravity="center"></CheckBox>
<TextView android:layout_weight="1" android:layout_width="0dip"></TextView>
</TableRow>
</TableLayout>
</LinearLayout>
If you want to show a keyboard with Capital case then instead of using android:inputType="textCapCharacters"
, you can use android:textAllCaps="true"
. Then your won't stick to the Uppercase format. Then to be sure that the input is in Uppercase, you can just call the toUpperCase()
method on the retrieved String from the EditText. Let me know your thoughts on this. Check this link for more clarity.
精彩评论