Skip to content

Instantly share code, notes, and snippets.

@Anurag--Singh
Last active January 19, 2017 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anurag--Singh/5a7e8ab1beaf8f5a8baec784df5c88e0 to your computer and use it in GitHub Desktop.
Save Anurag--Singh/5a7e8ab1beaf8f5a8baec784df5c88e0 to your computer and use it in GitHub Desktop.
View hide on Keyboard open or visible and can scroll the contents
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 1"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 2"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 3"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 4"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 5"
android:inputType="textNoSuggestions"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 6"
android:inputType="textNoSuggestions"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 7"
android:inputType="textNoSuggestions"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 8"
android:inputType="textNoSuggestions"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 9"
android:inputType="textNoSuggestions"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 10"
android:inputType="textNoSuggestions"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 11"
android:inputType="textNoSuggestions"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:hint="EditText 12"
android:inputType="textNoSuggestions"
/>
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
/>
<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I don't want to push this TextView and Button to above keyboard when keyboard is shown. Just obly want to push the ScrollView that contain all EditText"
android:textColor="#000"
/>
</LinearLayout>
<activity
android:name=".TestActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
compile 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.0.1'
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import net.yslibrary.android.keyboardvisibilityevent.KeyboardVisibilityEvent;
import net.yslibrary.android.keyboardvisibilityevent.KeyboardVisibilityEventListener;
public class TestActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
KeyboardVisibilityEvent.setEventListener(TestActivity.this,
new KeyboardVisibilityEventListener() {
@Override
public void onVisibilityChanged(boolean isOpen) {
// some code depending on keyboard visiblity status
if (isOpen) {
findViewById(R.id.button).setVisibility(View.GONE);
findViewById(R.id.text_view).setVisibility(View.GONE);
} else {
findViewById(R.id.button).setVisibility(View.VISIBLE);
findViewById(R.id.text_view).setVisibility(View.VISIBLE);
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment