JAVA CODE:
mEdtTextPickup.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
mLayoutDrop.invalidate();
mEdtTextPickup.bringToFront();
}
}
});
mEdtTextDrop.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
mLayoutPickup.invalidate();
mEdtTextDrop.bringToFront();
}
}
});
`
I have two layouts in my application Source and Destination in which one overlaps the other inside a FrameLayout.(just like the attached image)
Now how do i bring destination layout on top of source layout animated when it is focused. I googled a lot but found no solutions.
You can use a focus change listener to identify when the field is focused and then bringToFront to bring the view above the others.
destinationEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
edittext.bringToFront();
}
}
});
Related
I have a small problem with Edittext, I have two edittext and when I press an edittext the other must be cleaned, try to do it with isFocusable () but I can't, who can help me?
public void loadED(View view) {
if (edt4.isFocusable()) {
edt3.setText("");
} else {
if (edt3.isFocusable()) {
edt4.setText("");
}
}
}
Use an OnFocusChangeListener applied to each EditText:
edt4.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
edt3.getText().clear();
}
}
});
edt3.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
edt4.getText().clear();
}
}
});
Can any of you show me the best way to change the TextSize attribute of an EditText just when the user has it selected (is writing)?
This is what i accomplished so far:
I've two EditText in a linear layout.
xml:
<EditText
android:textSize="20dp"
android:onClick="makeTextViewFocusedBigger"/>
<EditText
android:textSize="20dp"
android:onClick="makeTextViewFocusedBigger"/>
activity:
public void makeTextViewFocusedBigger(View view) {
((EditText) view).setTextSize(TypedValue.COMPLEX_UNIT_DIP, 25);
}
When the user select it it does become bigger, but obviously it does not go back to the original size when the user stop using it.
What would you do to realize this function?
Use View.OnFocusChangedListener
myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
// Change size based on hasFocus boolean
}
});
Use setOnFocusChangeListener
Like This :
Your_Edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
{
Your_Edittext.setTextSize(25); //increased size
}
else
{
Your_Edittext.setTextSize(15); //normal size
}
}
});
Do following :
XML:
<EditText
android:textSize="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edit_text_first"/>
<EditText
android:textSize="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edit_text_second"/>
Activity OnCreate:
EditText editFirst=findViewById(R.id.edit_first)
EditText editSecond=findViewById(R.id.edit_second)
editFirst.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
// Change size of text inside 1st EditText
}
});
editSecond.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
// Change size of text inside 2nd EditText
}
});
To implement it more general :
public class MainActivity extends AppCompatActivity implements View.OnFocusChangeListener{
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editFirst.setOnFocusChangeListener(this);
editSecond.setOnFocusChangeListener(this);
}
#Override
public void onFocusChange(View v, boolean hasFocus)
{
// Change text size of every EditText or for selective EditText. As You want
}
}
You need to implement View.OnFocusChangeListener(). This method is called when the focus state of a view has changed.
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
{
// Change size when editText has focus
editText.setTextSize(30);
}else
{
// Change size when editText doesn't has focus
editText.setTextSize(15);
}
}
});
You have to implementView.OnFocusChangeListener() method , set the textview size according you want in onFocusChange()
myEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
// set the text size here
}
});
You need to addFocusChangedListener to your EditTexts. In them you can see if they are focused or not.
I have two EditTexts in an activity. I am trying to implement it so that when one EditText is focused, the second one looks like it is focused too (the underline must be bold as it is when EditText is focused).
I am trying to change underline like this when focus changes:
editText1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
// here editText2 must have not state
} else {
// here editText2 must have not state
}
}
});
But how can I make the underline bold on another text without it actually receiving focus?
Try this
editText1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
editText2.setTypeface(Typeface.NORMAL);
} else {
editText2.setTypeface(Typeface.DEFAULT_BOLD);
}
}
});
I have three different Edit Text with restriction of entering only numeric values, thus tapping on any one of the Edit Text opens NUMERIC KEYBOARD.
I tried to implement setOnFocusChangeListener for all Edit Text which ensures that when user tap anywhere outside any of the Edit Text hide the keyboard.
editText1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
editText2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
editText3.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
hideKeyboard(v);
}
}
});
And here is the implementation of 'hideKeyBoard'
public void hideKeyboard(View view) {
InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
This works fine, however, when I change focus from one EditText to another EditText, keyboard hides. This behaviour might be frustrating for user.
How can I deal with it and avoid unnecessary hiding of keyboard.
P.S I need to ensure that keyboard is numeric not alphabetical in any case.
Thank you MarianoZorrila for correcting me on my approach to the problem.Here are the changes I performed to solve this problem.
Gave an Id to my Relative Layout
<RelativeLayout
...
...
android:id="#+id/parent">
Modifications to Java File
View parent = findViewById(R.id.parent);
parent.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
hideKeyboard(view);
}
}
});
my Submitted application for amazon fire TV failed for the following reason :
Issue 1: Interactive portions of the screen are not highlighted when selected : Rewind, Fast Forward, and Play buttons above progress bar can be navigated and selected but no highlighted cursor is visible.
I am using the default media controller class provided by android and it does not provide this functionality.
I was able to catch the controls but i was not able to add a highlight on key down and remove it on key up. can anyone help with this?
Try this may be it works..
Field ffwd = MediaController.class.getDeclaredField("mFfwdButton");
Field rwd = MediaController.class.getDeclaredField("mRewButton");
Field playPause = MediaController.class.getDeclaredField("mPauseButton");
//System.out.println(f.get(d));//not accessible now
ffwd.setAccessible(true);//Abracadabra
rwd.setAccessible(true);//Abracadabra
playPause.setAccessible(true);
//System.out.println("Fusioni"+ffwd.get(mediaController)+" "+f1.get(mediaController));//now its ok
ffwdBtn = (ImageButton) ffwd.get(mediaController);
rwdBtn = (ImageButton) rwd.get(mediaController);
playPauseBtn = (ImageButton) playPause.get(mediaController);
//Log.i("imbtn",""+imbtn);
ffwdBtn.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
v.setBackgroundResource(R.drawable.round_background_selected);
else
v.setBackgroundColor(Color.TRANSPARENT);
}
});
rwdBtn.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
v.setBackgroundResource(R.drawable.round_background_selected);
else
v.setBackgroundColor(Color.TRANSPARENT);
}
});
playPauseBtn.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus)
v.setBackgroundResource(R.drawable.round_background_selected);
else
v.setBackgroundColor(Color.TRANSPARENT);
}
});
playPauseBtn.setBackgroundResource(R.drawable.round_background_selected);
rwdBtn.setBackgroundColor(Color.TRANSPARENT);
ffwdBtn.setBackgroundColor(Color.TRANSPARENT);
playPauseBtn.setFocusable(true);
playPauseBtn.requestFocus();