A keyboard is invisible when i touch on AppCompatEditText












0















I created the class ComplexEditText, which is extended from AppCompatEditText. I settled down my variant of background:



 setBackground(getResources().getDrawable(R.drawable.backgroundedittext));


I settled down padding:



setPadding((int) (16 * scale), (int) (10 * scale), (int) (17 * scale), (int) (13 * scale));


I created the button to clear the input text



mClearButtonImage = ResourcesCompat.getDrawable(getResources(), R.mipmap.delete_button, null);


But the problem is that the keyboard doesn't open when i touch on my custom view (extend from AppCompatEditText). i tried:



setClickable(true)
setFocusable(true)
setShowSoftInputOnFocus(true);
nputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);


I settled in AndroidManifes.xml:



android:windowSoftInputMode="adjustResize" 


It doesn't work too. The keyboard doesn't appear.



AndroidManifest.xml



    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.royallogistics.yegor.royallogistics">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".service.AppChannel"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".LoginActivity" />
<activity android:name=".SubordersDinamicsFields"
android:windowSoftInputMode="stateVisible">

</activity>


ComplexEditText.java



package com.royallogistics.yegor.royallogistics.RestyleView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.royallogistics.yegor.royallogistics.R;
import com.royallogistics.yegor.royallogistics.service.DependentFields;

import java.util.List;

@SuppressLint("ViewConstructor")
public class ComplexEditText extends AppCompatEditText {

// { НЕОБХОДИМЫЕ ПОЛЯ ДЛЯ УПРАВЛЕНИЯ }
private Integer mIndex_on_the_view;
private Integer mField_id;
@Nullable
private Integer mContainer_id;
@Nullable
private List<DependentFields> mActions;

Drawable mClearButtonImage;
EditText text;
float scale = getResources().getDisplayMetrics().density;

void init() {
mClearButtonImage = ResourcesCompat.getDrawable(getResources(), R.mipmap.delete_button, null);
setBackground(getResources().getDrawable(R.drawable.backgroundedittext));
setPadding((int) (16 * scale), (int) (10 * scale), (int) (17 * scale), (int) (13 * scale));
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
setShowSoftInputOnFocus(true);


// TODO: if the clear (X) button is tapped, clear the text
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {

Log.e("focus", getFullName() + " _ " + String.valueOf(getShowSoftInputOnFocus()));

if ((getCompoundDrawablesRelative()[2] != null)) {
float clearButtonStart; // Used for LTR languages
float clearButtonEnd; // Used for RTL languages
boolean isClearButtonClicked = false;
// TODO: Detect the touch in RTL or LTR layout direction.
if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
// If RTL, get the end of the button on the left side.
clearButtonEnd = mClearButtonImage
.getIntrinsicWidth() + getPaddingStart();
// If the touch occurred before the end of the button,
// set isClearButtonClicked to true.
if (event.getX() < clearButtonEnd) {
isClearButtonClicked = true;
}
} else {
// Layout is LTR.
// Get the start of the button on the right side.
clearButtonStart = (getWidth() - getPaddingEnd()
- mClearButtonImage.getIntrinsicWidth());
// If the touch occurred after the start of the button,
// set isClearButtonClicked to true.
if (event.getX() > clearButtonStart) {
isClearButtonClicked = true;
}
}
// TODO: Check for actions if the button is tapped.

if (isClearButtonClicked) {
// Check for ACTION_DOWN (always occurs before ACTION_UP).
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Switch to the black version of clear button.
mClearButtonImage =
ResourcesCompat.getDrawable(getResources(),
R.mipmap.delete_button, null);
showClearButton();
}
// Check for ACTION_UP.
if (event.getAction() == MotionEvent.ACTION_UP) {
// Switch to the opaque version of clear button.
mClearButtonImage =
ResourcesCompat.getDrawable(getResources(),
R.mipmap.delete_button, null);
// Clear the text and hide the clear button.
getText().clear();
hideClearButton();
return true;
}
} else {
return false;
}
}
return false;
}
});
// TODO: if the changes, show or hide the clear (X) button
addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
showClearButton();
}

@Override
public void afterTextChanged(Editable s) {
}
});
}

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return super.onCreateInputConnection(outAttrs);
}

public ComplexEditText(Context context, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();

}

public ComplexEditText(Context context, @Nullable AttributeSet attrs, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context, attrs);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();


}

public ComplexEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context, attrs, defStyleAttr);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();

}


private void setupAttributes(AttributeSet attributeSet) {
@SuppressLint("CustomViewStyleable") TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.ComplexEditTextattr);
typedArray.recycle();
}

String getFullName() {
if (mContainer_id != null) {
Log.e("Полное название", "field_" + String.valueOf(mField_id) + "_" + String.valueOf(mContainer_id));
return "field_" + String.valueOf(mField_id) + "_" + String.valueOf(mContainer_id);

} else {
Log.e("Полное название", "field_" + String.valueOf(mField_id));
return "field_" + String.valueOf(mField_id);

}
}

void clearField() {
setText("");
}

Integer getValueInteger() {
return Integer.valueOf(getText().toString());
}

String getValueString() {
return String.valueOf(getText().toString());
}

private void showClearButton() {

setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, mClearButtonImage, null);
}

private void hideClearButton() {
setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, null, null);
}


@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

}


screenshot with ComplexEditText










share|improve this question























  • Have you tried on a physical device or just the emulator ?

    – 113408
    Jan 19 at 14:15











  • @113408 i have tried on the emulator and a physical device

    – Dorokhov Yegor
    Jan 19 at 14:27
















0















I created the class ComplexEditText, which is extended from AppCompatEditText. I settled down my variant of background:



 setBackground(getResources().getDrawable(R.drawable.backgroundedittext));


I settled down padding:



setPadding((int) (16 * scale), (int) (10 * scale), (int) (17 * scale), (int) (13 * scale));


I created the button to clear the input text



mClearButtonImage = ResourcesCompat.getDrawable(getResources(), R.mipmap.delete_button, null);


But the problem is that the keyboard doesn't open when i touch on my custom view (extend from AppCompatEditText). i tried:



setClickable(true)
setFocusable(true)
setShowSoftInputOnFocus(true);
nputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);


I settled in AndroidManifes.xml:



android:windowSoftInputMode="adjustResize" 


It doesn't work too. The keyboard doesn't appear.



AndroidManifest.xml



    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.royallogistics.yegor.royallogistics">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".service.AppChannel"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".LoginActivity" />
<activity android:name=".SubordersDinamicsFields"
android:windowSoftInputMode="stateVisible">

</activity>


ComplexEditText.java



package com.royallogistics.yegor.royallogistics.RestyleView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.royallogistics.yegor.royallogistics.R;
import com.royallogistics.yegor.royallogistics.service.DependentFields;

import java.util.List;

@SuppressLint("ViewConstructor")
public class ComplexEditText extends AppCompatEditText {

// { НЕОБХОДИМЫЕ ПОЛЯ ДЛЯ УПРАВЛЕНИЯ }
private Integer mIndex_on_the_view;
private Integer mField_id;
@Nullable
private Integer mContainer_id;
@Nullable
private List<DependentFields> mActions;

Drawable mClearButtonImage;
EditText text;
float scale = getResources().getDisplayMetrics().density;

void init() {
mClearButtonImage = ResourcesCompat.getDrawable(getResources(), R.mipmap.delete_button, null);
setBackground(getResources().getDrawable(R.drawable.backgroundedittext));
setPadding((int) (16 * scale), (int) (10 * scale), (int) (17 * scale), (int) (13 * scale));
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
setShowSoftInputOnFocus(true);


// TODO: if the clear (X) button is tapped, clear the text
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {

Log.e("focus", getFullName() + " _ " + String.valueOf(getShowSoftInputOnFocus()));

if ((getCompoundDrawablesRelative()[2] != null)) {
float clearButtonStart; // Used for LTR languages
float clearButtonEnd; // Used for RTL languages
boolean isClearButtonClicked = false;
// TODO: Detect the touch in RTL or LTR layout direction.
if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
// If RTL, get the end of the button on the left side.
clearButtonEnd = mClearButtonImage
.getIntrinsicWidth() + getPaddingStart();
// If the touch occurred before the end of the button,
// set isClearButtonClicked to true.
if (event.getX() < clearButtonEnd) {
isClearButtonClicked = true;
}
} else {
// Layout is LTR.
// Get the start of the button on the right side.
clearButtonStart = (getWidth() - getPaddingEnd()
- mClearButtonImage.getIntrinsicWidth());
// If the touch occurred after the start of the button,
// set isClearButtonClicked to true.
if (event.getX() > clearButtonStart) {
isClearButtonClicked = true;
}
}
// TODO: Check for actions if the button is tapped.

if (isClearButtonClicked) {
// Check for ACTION_DOWN (always occurs before ACTION_UP).
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Switch to the black version of clear button.
mClearButtonImage =
ResourcesCompat.getDrawable(getResources(),
R.mipmap.delete_button, null);
showClearButton();
}
// Check for ACTION_UP.
if (event.getAction() == MotionEvent.ACTION_UP) {
// Switch to the opaque version of clear button.
mClearButtonImage =
ResourcesCompat.getDrawable(getResources(),
R.mipmap.delete_button, null);
// Clear the text and hide the clear button.
getText().clear();
hideClearButton();
return true;
}
} else {
return false;
}
}
return false;
}
});
// TODO: if the changes, show or hide the clear (X) button
addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
showClearButton();
}

@Override
public void afterTextChanged(Editable s) {
}
});
}

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return super.onCreateInputConnection(outAttrs);
}

public ComplexEditText(Context context, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();

}

public ComplexEditText(Context context, @Nullable AttributeSet attrs, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context, attrs);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();


}

public ComplexEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context, attrs, defStyleAttr);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();

}


private void setupAttributes(AttributeSet attributeSet) {
@SuppressLint("CustomViewStyleable") TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.ComplexEditTextattr);
typedArray.recycle();
}

String getFullName() {
if (mContainer_id != null) {
Log.e("Полное название", "field_" + String.valueOf(mField_id) + "_" + String.valueOf(mContainer_id));
return "field_" + String.valueOf(mField_id) + "_" + String.valueOf(mContainer_id);

} else {
Log.e("Полное название", "field_" + String.valueOf(mField_id));
return "field_" + String.valueOf(mField_id);

}
}

void clearField() {
setText("");
}

Integer getValueInteger() {
return Integer.valueOf(getText().toString());
}

String getValueString() {
return String.valueOf(getText().toString());
}

private void showClearButton() {

setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, mClearButtonImage, null);
}

private void hideClearButton() {
setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, null, null);
}


@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

}


screenshot with ComplexEditText










share|improve this question























  • Have you tried on a physical device or just the emulator ?

    – 113408
    Jan 19 at 14:15











  • @113408 i have tried on the emulator and a physical device

    – Dorokhov Yegor
    Jan 19 at 14:27














0












0








0








I created the class ComplexEditText, which is extended from AppCompatEditText. I settled down my variant of background:



 setBackground(getResources().getDrawable(R.drawable.backgroundedittext));


I settled down padding:



setPadding((int) (16 * scale), (int) (10 * scale), (int) (17 * scale), (int) (13 * scale));


I created the button to clear the input text



mClearButtonImage = ResourcesCompat.getDrawable(getResources(), R.mipmap.delete_button, null);


But the problem is that the keyboard doesn't open when i touch on my custom view (extend from AppCompatEditText). i tried:



setClickable(true)
setFocusable(true)
setShowSoftInputOnFocus(true);
nputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);


I settled in AndroidManifes.xml:



android:windowSoftInputMode="adjustResize" 


It doesn't work too. The keyboard doesn't appear.



AndroidManifest.xml



    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.royallogistics.yegor.royallogistics">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".service.AppChannel"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".LoginActivity" />
<activity android:name=".SubordersDinamicsFields"
android:windowSoftInputMode="stateVisible">

</activity>


ComplexEditText.java



package com.royallogistics.yegor.royallogistics.RestyleView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.royallogistics.yegor.royallogistics.R;
import com.royallogistics.yegor.royallogistics.service.DependentFields;

import java.util.List;

@SuppressLint("ViewConstructor")
public class ComplexEditText extends AppCompatEditText {

// { НЕОБХОДИМЫЕ ПОЛЯ ДЛЯ УПРАВЛЕНИЯ }
private Integer mIndex_on_the_view;
private Integer mField_id;
@Nullable
private Integer mContainer_id;
@Nullable
private List<DependentFields> mActions;

Drawable mClearButtonImage;
EditText text;
float scale = getResources().getDisplayMetrics().density;

void init() {
mClearButtonImage = ResourcesCompat.getDrawable(getResources(), R.mipmap.delete_button, null);
setBackground(getResources().getDrawable(R.drawable.backgroundedittext));
setPadding((int) (16 * scale), (int) (10 * scale), (int) (17 * scale), (int) (13 * scale));
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
setShowSoftInputOnFocus(true);


// TODO: if the clear (X) button is tapped, clear the text
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {

Log.e("focus", getFullName() + " _ " + String.valueOf(getShowSoftInputOnFocus()));

if ((getCompoundDrawablesRelative()[2] != null)) {
float clearButtonStart; // Used for LTR languages
float clearButtonEnd; // Used for RTL languages
boolean isClearButtonClicked = false;
// TODO: Detect the touch in RTL or LTR layout direction.
if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
// If RTL, get the end of the button on the left side.
clearButtonEnd = mClearButtonImage
.getIntrinsicWidth() + getPaddingStart();
// If the touch occurred before the end of the button,
// set isClearButtonClicked to true.
if (event.getX() < clearButtonEnd) {
isClearButtonClicked = true;
}
} else {
// Layout is LTR.
// Get the start of the button on the right side.
clearButtonStart = (getWidth() - getPaddingEnd()
- mClearButtonImage.getIntrinsicWidth());
// If the touch occurred after the start of the button,
// set isClearButtonClicked to true.
if (event.getX() > clearButtonStart) {
isClearButtonClicked = true;
}
}
// TODO: Check for actions if the button is tapped.

if (isClearButtonClicked) {
// Check for ACTION_DOWN (always occurs before ACTION_UP).
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Switch to the black version of clear button.
mClearButtonImage =
ResourcesCompat.getDrawable(getResources(),
R.mipmap.delete_button, null);
showClearButton();
}
// Check for ACTION_UP.
if (event.getAction() == MotionEvent.ACTION_UP) {
// Switch to the opaque version of clear button.
mClearButtonImage =
ResourcesCompat.getDrawable(getResources(),
R.mipmap.delete_button, null);
// Clear the text and hide the clear button.
getText().clear();
hideClearButton();
return true;
}
} else {
return false;
}
}
return false;
}
});
// TODO: if the changes, show or hide the clear (X) button
addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
showClearButton();
}

@Override
public void afterTextChanged(Editable s) {
}
});
}

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return super.onCreateInputConnection(outAttrs);
}

public ComplexEditText(Context context, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();

}

public ComplexEditText(Context context, @Nullable AttributeSet attrs, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context, attrs);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();


}

public ComplexEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context, attrs, defStyleAttr);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();

}


private void setupAttributes(AttributeSet attributeSet) {
@SuppressLint("CustomViewStyleable") TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.ComplexEditTextattr);
typedArray.recycle();
}

String getFullName() {
if (mContainer_id != null) {
Log.e("Полное название", "field_" + String.valueOf(mField_id) + "_" + String.valueOf(mContainer_id));
return "field_" + String.valueOf(mField_id) + "_" + String.valueOf(mContainer_id);

} else {
Log.e("Полное название", "field_" + String.valueOf(mField_id));
return "field_" + String.valueOf(mField_id);

}
}

void clearField() {
setText("");
}

Integer getValueInteger() {
return Integer.valueOf(getText().toString());
}

String getValueString() {
return String.valueOf(getText().toString());
}

private void showClearButton() {

setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, mClearButtonImage, null);
}

private void hideClearButton() {
setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, null, null);
}


@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

}


screenshot with ComplexEditText










share|improve this question














I created the class ComplexEditText, which is extended from AppCompatEditText. I settled down my variant of background:



 setBackground(getResources().getDrawable(R.drawable.backgroundedittext));


I settled down padding:



setPadding((int) (16 * scale), (int) (10 * scale), (int) (17 * scale), (int) (13 * scale));


I created the button to clear the input text



mClearButtonImage = ResourcesCompat.getDrawable(getResources(), R.mipmap.delete_button, null);


But the problem is that the keyboard doesn't open when i touch on my custom view (extend from AppCompatEditText). i tried:



setClickable(true)
setFocusable(true)
setShowSoftInputOnFocus(true);
nputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);


I settled in AndroidManifes.xml:



android:windowSoftInputMode="adjustResize" 


It doesn't work too. The keyboard doesn't appear.



AndroidManifest.xml



    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.royallogistics.yegor.royallogistics">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:name=".service.AppChannel"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".LoginActivity" />
<activity android:name=".SubordersDinamicsFields"
android:windowSoftInputMode="stateVisible">

</activity>


ComplexEditText.java



package com.royallogistics.yegor.royallogistics.RestyleView;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.royallogistics.yegor.royallogistics.R;
import com.royallogistics.yegor.royallogistics.service.DependentFields;

import java.util.List;

@SuppressLint("ViewConstructor")
public class ComplexEditText extends AppCompatEditText {

// { НЕОБХОДИМЫЕ ПОЛЯ ДЛЯ УПРАВЛЕНИЯ }
private Integer mIndex_on_the_view;
private Integer mField_id;
@Nullable
private Integer mContainer_id;
@Nullable
private List<DependentFields> mActions;

Drawable mClearButtonImage;
EditText text;
float scale = getResources().getDisplayMetrics().density;

void init() {
mClearButtonImage = ResourcesCompat.getDrawable(getResources(), R.mipmap.delete_button, null);
setBackground(getResources().getDrawable(R.drawable.backgroundedittext));
setPadding((int) (16 * scale), (int) (10 * scale), (int) (17 * scale), (int) (13 * scale));
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT);
setShowSoftInputOnFocus(true);


// TODO: if the clear (X) button is tapped, clear the text
setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {

Log.e("focus", getFullName() + " _ " + String.valueOf(getShowSoftInputOnFocus()));

if ((getCompoundDrawablesRelative()[2] != null)) {
float clearButtonStart; // Used for LTR languages
float clearButtonEnd; // Used for RTL languages
boolean isClearButtonClicked = false;
// TODO: Detect the touch in RTL or LTR layout direction.
if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
// If RTL, get the end of the button on the left side.
clearButtonEnd = mClearButtonImage
.getIntrinsicWidth() + getPaddingStart();
// If the touch occurred before the end of the button,
// set isClearButtonClicked to true.
if (event.getX() < clearButtonEnd) {
isClearButtonClicked = true;
}
} else {
// Layout is LTR.
// Get the start of the button on the right side.
clearButtonStart = (getWidth() - getPaddingEnd()
- mClearButtonImage.getIntrinsicWidth());
// If the touch occurred after the start of the button,
// set isClearButtonClicked to true.
if (event.getX() > clearButtonStart) {
isClearButtonClicked = true;
}
}
// TODO: Check for actions if the button is tapped.

if (isClearButtonClicked) {
// Check for ACTION_DOWN (always occurs before ACTION_UP).
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Switch to the black version of clear button.
mClearButtonImage =
ResourcesCompat.getDrawable(getResources(),
R.mipmap.delete_button, null);
showClearButton();
}
// Check for ACTION_UP.
if (event.getAction() == MotionEvent.ACTION_UP) {
// Switch to the opaque version of clear button.
mClearButtonImage =
ResourcesCompat.getDrawable(getResources(),
R.mipmap.delete_button, null);
// Clear the text and hide the clear button.
getText().clear();
hideClearButton();
return true;
}
} else {
return false;
}
}
return false;
}
});
// TODO: if the changes, show or hide the clear (X) button
addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
showClearButton();
}

@Override
public void afterTextChanged(Editable s) {
}
});
}

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return super.onCreateInputConnection(outAttrs);
}

public ComplexEditText(Context context, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();

}

public ComplexEditText(Context context, @Nullable AttributeSet attrs, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context, attrs);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();


}

public ComplexEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr, Integer mIndex_on_the_view, Integer mField_id, @Nullable Integer mContainer_id, @Nullable List<DependentFields> mActions) {
super(context, attrs, defStyleAttr);
this.mIndex_on_the_view = mIndex_on_the_view;
this.mField_id = mField_id;
this.mContainer_id = mContainer_id;
this.mActions = mActions;
init();

}


private void setupAttributes(AttributeSet attributeSet) {
@SuppressLint("CustomViewStyleable") TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.ComplexEditTextattr);
typedArray.recycle();
}

String getFullName() {
if (mContainer_id != null) {
Log.e("Полное название", "field_" + String.valueOf(mField_id) + "_" + String.valueOf(mContainer_id));
return "field_" + String.valueOf(mField_id) + "_" + String.valueOf(mContainer_id);

} else {
Log.e("Полное название", "field_" + String.valueOf(mField_id));
return "field_" + String.valueOf(mField_id);

}
}

void clearField() {
setText("");
}

Integer getValueInteger() {
return Integer.valueOf(getText().toString());
}

String getValueString() {
return String.valueOf(getText().toString());
}

private void showClearButton() {

setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, mClearButtonImage, null);
}

private void hideClearButton() {
setCompoundDrawablesRelativeWithIntrinsicBounds(null, null, null, null);
}


@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

}


screenshot with ComplexEditText







java android android-studio keyboard






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 19 at 14:06









Dorokhov YegorDorokhov Yegor

32




32













  • Have you tried on a physical device or just the emulator ?

    – 113408
    Jan 19 at 14:15











  • @113408 i have tried on the emulator and a physical device

    – Dorokhov Yegor
    Jan 19 at 14:27



















  • Have you tried on a physical device or just the emulator ?

    – 113408
    Jan 19 at 14:15











  • @113408 i have tried on the emulator and a physical device

    – Dorokhov Yegor
    Jan 19 at 14:27

















Have you tried on a physical device or just the emulator ?

– 113408
Jan 19 at 14:15





Have you tried on a physical device or just the emulator ?

– 113408
Jan 19 at 14:15













@113408 i have tried on the emulator and a physical device

– Dorokhov Yegor
Jan 19 at 14:27





@113408 i have tried on the emulator and a physical device

– Dorokhov Yegor
Jan 19 at 14:27












1 Answer
1






active

oldest

votes


















0














i add the following line in the constructor:



clearFocus();


and i add the following code in the onTouch method:



                requestFocus();
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267908%2fa-keyboard-is-invisible-when-i-touch-on-appcompatedittext%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    i add the following line in the constructor:



    clearFocus();


    and i add the following code in the onTouch method:



                    requestFocus();
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);





    share|improve this answer




























      0














      i add the following line in the constructor:



      clearFocus();


      and i add the following code in the onTouch method:



                      requestFocus();
      InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);





      share|improve this answer


























        0












        0








        0







        i add the following line in the constructor:



        clearFocus();


        and i add the following code in the onTouch method:



                        requestFocus();
        InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);





        share|improve this answer













        i add the following line in the constructor:



        clearFocus();


        and i add the following code in the onTouch method:



                        requestFocus();
        InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 19 at 15:49









        Dorokhov YegorDorokhov Yegor

        32




        32






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267908%2fa-keyboard-is-invisible-when-i-touch-on-appcompatedittext%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Homophylophilia

            Updating UILabel text programmatically using a function

            Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage