Skip to content

Commit

Permalink
Close keyboard when Navigation bar is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
itsyourap committed Jun 16, 2024
1 parent db542e9 commit ec9a5cc
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions app/src/main/java/sayan/apps/numplex/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package sayan.apps.numplex

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.MenuItem
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment
import com.google.android.material.navigation.NavigationView
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.material.navigation.NavigationView
import com.google.firebase.auth.FirebaseAuth
import android.content.Intent
import android.widget.TextView
import com.squareup.picasso.Picasso

class MainActivity : AppCompatActivity() {
Expand Down Expand Up @@ -62,6 +64,10 @@ class MainActivity : AppCompatActivity() {
mGoogleSignInClient = GoogleSignIn.getClient(this, gso)

drawerLayout = findViewById(R.id.drawerLayout)
drawerLayout.addDrawerListener(object : DrawerLayout.SimpleDrawerListener() {
// Close the keyboard when the drawer starts moving
override fun onDrawerStateChanged(newState: Int) = closeKeyboard()
})
val navView: NavigationView = findViewById(R.id.navView)
toggle = ActionBarDrawerToggle(this, drawerLayout, R.string.open, R.string.close)
drawerLayout.addDrawerListener(toggle)
Expand Down Expand Up @@ -113,7 +119,11 @@ class MainActivity : AppCompatActivity() {
}

R.id.nav_update -> {
Toast.makeText(applicationContext, "Latest Version is already Installed !!", Toast.LENGTH_SHORT).show()
Toast.makeText(
applicationContext,
"Latest Version is already Installed !!",
Toast.LENGTH_SHORT
).show()
}

R.id.nav_feedback -> {
Expand All @@ -128,6 +138,14 @@ class MainActivity : AppCompatActivity() {
}
}

private fun closeKeyboard() {
val view = this.currentFocus
if (view != null) {
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
}

private fun goToSignInActivity() {
val intent = Intent(this, SignInActivity::class.java)
startActivity(intent)
Expand Down

0 comments on commit ec9a5cc

Please sign in to comment.