I have looked into this (extensively) on Android – there seems to be no method of changing the keyboard type, unless the keyboard is triggered by an Android UI input element. You CANNOT change it directly from C++, or even from a straight Java API. This is very frustrating.
There are dirty, horrible hacks with hidden UI input fields that can be used to work around this – none I felt comfortable attempting. This could change, though, with some change in the Android API. I’m interested if there is such a thing?
For iOS, I’m not sure – the lack of Android support stunted researching further
Well, I’ve managed to get it to work Unfortunately singmajesty was right and other keyboard types cannot be used without native UI elements
Here’s the code, it’s quite raw and it would be best to create an extension out of it, but I don’t have much time now
MainActivity.java:
public static MainActivity mainActivity;
private static EditText input;
private static FrameLayout targetFrame;
private static HaxeObject callback;
private static HaxeObject tf;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mainActivity = this;
LayoutParams lParamsMW = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1);
input = new EditText(this);
input.setLayoutParams(lParamsMW);
RelativeLayout wrapView = wrapView();
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
addContentView(wrapView, params);
targetFrame.addView(input);
input.addTextChangedListener(new TextWatcher()
{
@Override
public void afterTextChanged(Editable s)
{
Extension.callbackHandler.post(new Runnable() { public void run()
{
callback.call("onTextEdit", new Object[] {input.getText().toString(), tf});
}});
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
}
private RelativeLayout wrapView()
{
RelativeLayout parentLayout = new RelativeLayout(getApplicationContext());
parentLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
targetFrame = new FrameLayout (getApplicationContext());
RelativeLayout.LayoutParams targetFrameParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
parentLayout.addView(targetFrame, targetFrameParams);
parentLayout.setVisibility(View.GONE);
return parentLayout;
}
public static void showKeyboard(final HaxeObject _callback, final HaxeObject _tf, final String initText)
{
callback = _callback;
tf = _tf;
Extension.callbackHandler.post(new Runnable() { public void run()
{
input.setText(initText);
input.setSelection(input.getText().length());
input.setInputType(InputType.TYPE_CLASS_NUMBER); //change to desired soft keyboard type
input.requestFocusFromTouch();
mainActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
InputMethodManager imm = (InputMethodManager) mainActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(input, 0);
}});
}