I am trying to have my EditText Focused after the animation to expand it takes place. I tried programmicly setting the focus and in Xml have tried. I have run out of ideas that could fix this but someone out there has to know
MainActivity,
public void onSearchExpand(View view){
w_SearchBarFullScreen.setVisibility(View.VISIBLE);
SearchBarExpand = AnimationUtils.loadAnimation(MainActivity.this,R.anim.web_search_expand);
w_SearchBarFullScreen.startAnimation(SearchBarExpand);
w_Toolbar.startAnimation(FadeOut);
w_SearchBarFullScreen.setFocusable(true);
}
XMl,
<EditText
android:id="@+id/w_SearchBarFullScreen"
android:layout_width="360dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/web_search_bar"
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1"
android:singleLine="true"
android:text=" "
android:elevation="5dp"
android:focusable="true"
xmlns:android="http://schemas.android.com/apk/res/android" />
The end goal is that when the Animation finishes it will have the SoftKeyBoard visible and ready to type something into it.
Ended up figuring it out with this,
public void onSearchExpand(View view){
w_SearchBarFullScreen.setVisibility(View.VISIBLE);
SearchBarExpand = AnimationUtils.loadAnimation(MainActivity.this,R.anim.web_search_expand);
w_SearchBarFullScreen.startAnimation(SearchBarExpand);
w_Toolbar.startAnimation(FadeOut);
if(w_SearchBarFullScreen.getVisibility() == View.VISIBLE){
w_SearchBarFullScreen.requestFocus();
}
}
but now the issue is having the keyboard show with it getting focus any suggestions?
With the Use of a Animation Listener i am left with this error
01-31 13:35:27.411 5950-5950/com.example.mickeyt.onyxbrowser
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mickeyt.onyxbrowser, PID: 5950
java.lang.IllegalStateException: Could not execute method for
android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5623)
at android.view.View$PerformClick.run(View.java:22433)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5623)
at android.view.View$PerformClick.run(View.java:22433)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.animation.Animation.setAnimationListener(android.view.animation.Animation$AnimationListener)' on a null object reference
at com.example.mickeyt.onyxbrowser.MainActivity.onSearchExpand(MainActivity.java:338)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5623)
at android.view.View$PerformClick.run(View.java:22433)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6247)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Using this worked for me.
public void onSearchExpand(View view){
w_SearchBarFullScreen.setVisibility(View.VISIBLE);
w_SearchBarFullScreen.startAnimation(SearchBarExpand);
w_Toolbar.startAnimation(FadeOut);
if(w_SearchBarFullScreen.getVisibility() == View.VISIBLE){
w_SearchBarFullScreen.requestFocus();
w_SearchBarFullScreen.setText(" ");
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
assert imm != null;
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}