This is just a small test app/program I am working on that i plan to put into a larger app.
I Have an editText that is not clickable or focusable. I think this is the only way to make it so it wont open the keyboard via touch. The soft keyboard pops up with a button click and enables editing of the edit text.I want editText to become focused (the underline become blue) as soon as the button is clicked so the user knows they are in the field. As of now, only when they begin typing does the underline become blue. I feel like i am missing something obvious.
Also , depending on how I exit out of the app , sometimes when I come back to it , when I click the button, the button itself gets focus , and any typing does not appear in the editText.
<RelativeLayout 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"
tools:context="${relativePackage}.${activityClass}" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="110dp"
android:onClick="showKeyboard"
android:text="Button" />
<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_marginLeft="37dp"
android:ems="10"
android:clickable="FALSE">
<requestFocus />
</EditText>
</RelativeLayout>
JAVA
package com.example.textfield;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
Button btn;
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button1);
txt = (TextView) findViewById(R.id.editText1);
txt.setFocusable(false);
txt.setClickable(false);
//txt.setImeOptions(EditorInfo.IME_ACTION_DONE);
}
public void showKeyboard(View v) {
txt.setFocusable(true);
txt.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
}