How to show my layout in front off soft keyboard Android? - android

How to show my layout in front off soft keyboard Android like whatsapp or facebook?
like this
thanks before
this my code, but when emoji layout show, soft keyboard close.
btn_pop_emot.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (listEmot.getVisibility() == View.VISIBLE) {
listEmot.setVisibility(View.GONE);
imm.toggleSoftInputFromWindow(
edt_pop_komen.getApplicationWindowToken(),
InputMethodManager.SHOW_FORCED, 0);
btn_pop_emot.setBackgroundResource(R.drawable.emot_anim);
} else {
listEmot.setVisibility(View.VISIBLE);
imm.hideSoftInputFromWindow(edt_pop_komen.getWindowToken(),
0);
btn_pop_emot.setBackgroundResource(R.drawable.keyboard);
}
}
});

You can use this library, it also contains sample code in README to get you started
https://github.com/ankushsachdeva/emojicon

Related

customization of edit text and input type in android

I had customized edit text with floating label and i write a method to set input type which is working but for last edit text its showing number keyboard instead of normal keyboard take alook at my code
private void setFloatInputType(int inputType) {
if(inputType==16) {
input.setFocusable(false);
input.setOnFocusChangeListener(null);
input.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setDatePicker();
}
});
}
else
if(inputType==0) {
input.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
// input.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
Log.d("INput TYp3", "" + input.getInputType());
}
else
input.setInputType(inputType);
I had debug the code it showsthat for third text field input type is set to
normal keyboard but os is popup numberic keyboard.
any suggestion will be highly appreciated.
Thanks,
Try replacing
input.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
with
input.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);

Scrolling an android screen automatically with dynamic addition of widgets

I want to scroll a android screen dynamically by clicking a button. The scrollable content will be added dynamically. The screen shot i have attached. As shown in the screen shot i want to scroll the screen like the "Car details" label should be at the top of the screen.
sv.post(new Runnable()
{
#Override
public void run()
{
sv.fullScroll(View.FOCUS_DOWN);
vehicle_no.setFocusableInTouchMode(true);
vehicle_no.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(vehicle_no, InputMethodManager.SHOW_IMPLICIT);
}
});
This is the code that i am using to scroll the screen. But it's not solving my problem. Please suggest me a solution for this problem. Thank you.
Add car details
First add view and then call this
sv.postDelayed(new Runnable()
{ #Override
public void run()
{ your code } },500);

ankushsachdeva emojicon display over softkeyboard (Android)

I implemented the ankushsachdeva emojicon project to display emojicons in my chat app. When i click on a specific chat i start my ChatActivity. If i then immediately click the emoji-imageButton which i made, without expanding the keyboard first, it looks like the left screenshot here
Afterwords, the emojicon-overlay is always displayed correctly. (right screenshot)
I want the overlay to always be like in the right screenshot. Any ideas? (thanks in advance)
ChatActivity:
private ListView listView; //contains the chatmessages and has a customAdapter
private EmojiconsPopup popUp; //emojicon-popUp
private EditText editText; //editText to capture text and emojicons
private InputMethodManager inputManager;
#Override
protected void onCreate(Bundle savedInstanceState){
listView = (ListView) findViewById(R.id.listView);
//...//
inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
popUp = new EmojiconsPopup(listView, getApplicationContext());
popUp.setSizeForSoftKeyboard();
popUp.setOnEmojiconClickedListener(new OnEmojiconClickedListener(){
#Override
public void onEmojiconClicked(Emojicon emojicon){
editText.append(emojicon.getEmoji());
}
});
popUp.setOnEmojiconBackspaceClickedListener(new OnEmojiconBackspaceClickedListener(){
#Override
public void onEmojiconBackspaceClicked(View v){
KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
editText.dispatchKeyEvent(event);
}
});
popUp.setOnSoftKeyboardOpenCloseListener(new OnSoftKeyboardOpenCloseListener(){
#Override
public void onKeyboardOpen(int keyBoardHeight){
}
#Override
public void onKeyboardClose(){
if (popUp.isShowing())
popUp.dismiss();
}
});
}
//called when the emojicon button is clicked
public void onEmojiButtonClicked(View view){
if (!popUp.isShowing()){
inputManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
popUp.showAtBottom(); //show popUp with emojicons
}else if(popUp.isShowing()){
popUp.dismiss(); // hide popUp with emojicons
}
}
Since, there is no reliable way to know the soft keyboard height, the library calculates it by opening the keyboard and seeing how much the top most layout of the view heirarchy shrinks.
I have added a new function into the library showAtBottomPending() which should solve your problem.
Make the following two changes to your code.
Change your onEmojiButtonClicked function to
public void onEmojiButtonClicked(View view){
if (!popUp.isShowing()){
popUp.showAtBottomPending(); //show popUp with emojicons after the keyboard is visible
inputManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
}else if(popUp.isShowing()){
popUp.dismiss(); // hide popUp with emojicons
}
}
Instead of passing listView in the EmojiconsPopup constructor,
pass the top most layout of your view hierarchy.
use like this its working.
public void onEmojiButtonClicked(View view){
if (!popUp.isShowing()){
popUp.showAtBottomPending(); //show popUp with emojicons after the keyboard is visible
showKeyboard(ettext);
}else if(popUp.isShowing()){
popUp.dismiss(); // hide popUp with emojicons
}
}
public void showKeyboard(final EmojiconEditText ettext){
ettext.requestFocus();
ettext.postDelayed(new Runnable(){
#Override public void run(){
InputMethodManager keyboard=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(ettext,0);
}
}
,200);
}

How do I select all text when clicking on a EditText view?

so I tried android:selectAllOnFocus and of course I'm using android:hint.
The app loads, requestFocus triggers and the full text is selected.
The problem is that when I click in the EditText the selection is lost.
I've already read:
Select all text inside EditText when it gets focus
For some reason, it worked (on Jelly Bean) only if I posted it with a Handler:
new Handler().post(new Runnable() {
#Override
public void run() {
paidView.selectAll();
}
});
Set the selection in an View.OnClickListener like so:
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editText.setSelection(0, editText.getText().length() - 1);
}
}
Set the selection in an View.OnClickListener like so: (with the 0 and text length opposite to the previously approved response) - this will ensure that when the user starts typing the content will be overridden.
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editText.setSelection(editText.getText().length() - 1, 0);
}
}
I realize this is an old post, but I had this same problem. For me, the reasoning was that I like to move the keyboard out of the way (dismiss it) to get my bearings (or hit buttons to add or remove rows of data) and when i touched back on the EditText I was previously editing, it was annoying to have the keyboard pop back up and the text un-select, forcing me to either work to get the cursor to where I wanted to start deleting, or touch another EditText and then touch back on the original to re-select everything. I just want to have the keyboard pop back up and have the text selected and ready to overwrite whenever I go to that EditText.
There are easy solutions to this:
1) Long tap does this for you on most occasions.
2) If you're already using setSelectAllOnFocus(true), you can just throw a simple clearFocus() and requestFocus() in your onClick listener:
etMyEditText.setSelectAllOnFocus(true);
etMyEditText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
view.clearFocus();
view.requestFocus();
}
});
This way the EditText has everything selected when you tap on it, regardless of soft keyboard status.
Additional bonus:
Add android:windowSoftInputMode="adjustPan" inside your <activity .../> tag in your AndroidManifest.xml file to force the selected EditText to stay in sight when the soft keyboard pops up.
try This
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editText.selectAll();
//or this.selectAll();
}
To select all the text.
Do the code below after you did findViewById and you are good to go:
edtProductPrice.setSelectAllOnFocus(true);
edtProductPrice.requestFocus();
edtProductPrice.selectAll();

Customized keyboard

I am very new to developping Android application and I am facing a
difficulty.
What I want to do is to use a specific keyboard when I click on an
EditText. So far, I have found the Keyboard and KeyboardView
classes but I haven't succeeded to do what I want yet.
Here is the description of where I am :
I have described my keyboard in a XML file,
I create a "KeyboardView" object,
I initialize it with clavier=new KeyboardView(activité,
(AttributeSet)findViewById(R.xml.clavier_numerique));
but I don't know how to replace the standard keyboard with this
customized keyboard.
Am I doing something wrong? What else should I do?
Thanks in advance for the time you will spend trying to help me.
You should use something like this:
//retrieve the keyboard view from xml
kbdV= (KeyboardView) findViewById(R.id.kbd);
//set the keyboard layout to the layout you defined in res/xml/keyboard_layout.xml
kbdV.setKeyboard(new Keyboard(this,R.xml.keyboard_layout)); //defines the keyboard layout
//add a keyboard action listener
kbdV.setOnKeyboardActionListener(new KeyboardView.OnKeyboardActionListener(){
public void onKey(int primaryCode, int[] keyCodes) {
handlePress(primaryCode, keyCodes); // callback to handle keypresses
}
public void onPress(int primaryCode) {}
public void onRelease(int primaryCode) {}
public void onText(CharSequence text) {}
public void swipeDown() {}
public void swipeLeft() {}
public void swipeRight() {}
public void swipeUp() {}
});
with a layout xml file similar to this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- your widgets here -->
<KeyboardView android:id="#+id/kbd" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>
At first you should decide what you want from keyboard:
if you just want to change to numbers you can do that by the first answer from Macarse
if you want a complete customized keyboard you should use Keyboard and KeyboardView classes by a second project
You need to specify an inputType in the xml:
<EditText android:inputType="textUri"/>
or from the code doing:
EditText input;
input.setInputType(InputType.TYPE_CLASS_NUMBER);
You can read the available inputTypes here.
When you initialize it with clavier=new KeyboardView(activity,
(AttributeSet)findViewById(R.xml.clavier_numerique),EditText edit);
You can transfer the EditText object in. And hide the standard keyboard,show the customized KeyboardView like this.
public void showKeyboard() {
if (edit != null) {
InputMethodManager imm = (InputMethodManager)mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
}
keyboardView.setVisibility(View.VISIBLE);
keyboardView.setEnabled(true);
}

Categories

Resources