Change the default Button-Label on android Keyboard - java

Is it possible to change the label of the right-down button (OK-Button) in the default android-keyboard? I want to set my own text on it and I have tried the following code:
EditText et = (EditText) findviewById(...);
et.setImeOptions(EditorInfo.IME_ACTION_DONE);
et.setImeActionLabel("myLabel", EditorInfo.IME_ACTION_DONE);
However, the Label I see on the Button is the default from EditorInfo.IME_ACTION_DONE namely "OK". Should I adapt propely the above code, or is there another way to accomplish it?

You forgot
editText.setInputType(InputType.TYPE_CLASS_TEXT);
Otherwise the EditText defaults to TYPE_CLASS_TEXT | TYPE_TEXT_FLAG_MULTI_LINE, which always has the "enter as line break" key instead of IME_ACTION_DONE.

Related

How to remove Autofill in inputType editText

How to remove this recommendation TAB with previously used email Id that appears when i click on the edit text . Email Tags
How to make that color TRANSPARENT once I've selected one them.Selected Color
You can use this in your xml to disable the auto fill
android:importantForAutofill="no"
if it doesn't work, could you please include your EditText xml

java - radiogroup with on checked changed listener in fragment

I'm new to android programming. Maybe you can help me with this.
I've got:
Fragment
RadioGroup with 2 radio buttons
EditText
My goal is:
By default the first radio button is selected and the edittext was disabled or uneditable
then when i select the 2nd radio button it enables the edittext and setfocus to it
And also vice versa.
When i select again the first radio button it will disable the edittext.
This were all inside one of my fragments.
Can someone help me for the code?
Also another question, can i save the previously selected radio button using shared preferences so it will be loaded when i open my application?
Thanks in advance. :)
Ok first set your EditText in visible in xml or java using this code snippet android:visibility="invisible" or in java code myButton.setVisibility(View.INVISIBLE); while pressing the other radio button make it visible by using this code myButton.setVisibility(View.VISIBLE);
Then com e to your second question you can save your radio button selection using share preference by setting a variable
save
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("your_key", "yourValue");
editor.commit();
get
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
String myValue = sp.getString("your_key", "defaultValue");
The SharedPreference interface gives you access to the an xml file, and a easy way to modify it through its editor. The file is stored in /data/data/com.your.package/shared_prefs/ and you can access it onlu through this SharedPreference API

Error text on edittext box appears to be white

I have the following code:
EditText edit = (EditText) findViewById(R.id.bluetractor);
if (edit.getText().toString().equals("Blue Tractor"))
{
Toast.makeText(getApplicationContext(), "Correct", Toast.LENGTH_LONG).show();
}
else
{
edit.setError("Incorrect");
}
But when I click the button that executes the code, it all works well apart from the fact the writing (the "Incorrect") appears to be white and therefore it is not visible on the white background of the error popup. Can anyone help? Thanks
couldn't you either change the color in the XML for that view or
setError("error").setTextColor(bleh)
It can be done in xml by setting
<item name="android:textColorSecondaryInverse"></item>
Alternatively, you can use setError with a Spannable String

paste option for edittext

I have an edittext and I would like to paste some text in it. I can copy the text from some web page but I am not able to paste the text in my edittext control.How can I enable my edittext to paste some text.Here is my main.xml for edittext ;
enter code here
<EditText
android:id="#+id/enter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight= "2"
android:scrollbars="vertical"
android:textColor="#color/black"
/>
Thanks
This is on Android 4.4.2 Samsung S4;
Documentation for TextView says that:
To allow users to copy some or all of the TextView's value and paste
it somewhere else, set the XML attribute android:textIsSelectable to
"true" or call setTextIsSelectable(true). The textIsSelectable flag
allows users to make selection gestures in the TextView, which in turn
triggers the system's built-in copy/paste controls.
There is also another Textview attribure called android:cursorVisible which determines if the system should be invoked about the copy/paste callbacks.
By default I believe both of these are true and selection/copy/paste mechanics are already enabled. I could not change that behaviour by using android:textIsSelectable="false" but if I set android:cursorVisible="false" initially you can't paste anything inside the EditText. Only after you type something in, cursor and selection behaviour becomes enabled again. Maybe this should be handled inside the code rather than in the layout xmls, or it might be related to android:inputType which also did not make a difference for me.
So try setting android:cursorVisible="true" in your EditText's layout xml if paste is not enabled by default.
According to your problem if you copied some data any where in your system and you want to paste it in some specific variable, like Edit TextBox, Textview etc, then this code will surely help you.
ClipboardManager clipMan = (ClipboardManager)getSystemService(v.getContext().CLIPBOARD_SERVICE);
myEdtTxt.setText(clipMan.getText());
Note:- here the clipMan object will store the data whenever copied process take place and we will return that data from that object and will set it,
To enable the standard copy/paste for TextView, U can choose one of the following:
Change in layout file:
Either add below property to your TextView
android:textIsSelectable="true"
and In your Java class write this line to set it programmatically.
myTextView.setTextIsSelectable(true);
if fragment try with
mContext.myTextView.setTextIsSelectable(true);
And long press on the TextView you can see copy/paste action bar.
Try setting the inputType="text" for the EditText field

Can't get focus on editText when children are added in layout

i am adding a spinner, an image and an editText in a linearLayout everytime i click a button.
Now whenever i add this layout , editText shows blinking, means it has focus but the keyboard won't show up. Even i click on it, the keyboard won't show up. What most i can do is to click somewhere else and then back at the editText to make it show keyboard and proper focus.
I am using following code, how can i fix this bug.
viewHolder.title = (EditText) view.findViewById(R.id.AddNewDetail);
view.setTag(viewHolder);
layout.addView(view);
i think you should force the softkeyboard show.
((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(editText,
InputMethodManager.SHOW_FORCED);
and close it
((InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(editText.getWindowToken(),
0);
and focus on edittext
editText.requestFocus();
May you have added the below line in for your activity in manifeast file
android:windowSoftInputMode="stateHidden"
try removing it or you can manaually use the requestfocus method to get focus. try the below method.
edittext.requestFocus();

Categories

Resources