Commit 86480fca by Paktalin

Keyboard is hidden after adding a new word

parent 70e56d3c
......@@ -11,6 +11,10 @@ import com.google.firebase.firestore.FirebaseFirestore
import com.paktalin.vocabularynotebook.R
import kotlinx.android.synthetic.main.activity_main.*
import android.view.WindowManager
import android.app.Activity
import android.view.View
import android.view.inputmethod.InputMethodManager
class MainActivity : AppCompatActivity() {
......@@ -60,6 +64,15 @@ class MainActivity : AppCompatActivity() {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
}
fun hideKeyboard(activity: Activity) {
val imm = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
var view = activity.currentFocus
if (view == null) {
view = View(activity)
}
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
companion object {
private val TAG = "VN/" + MainActivity::class.simpleName
}
......
......@@ -8,6 +8,7 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageButton
import android.widget.Toast
import com.google.firebase.firestore.FirebaseFirestore
......@@ -62,17 +63,18 @@ class NewWordFragment : Fragment() {
}
private fun showAddWordButton() {
activity!!.findViewById<ImageButton>(R.id.btnAddWord).visibility = View.VISIBLE }
activity!!.findViewById<FrameLayout>(R.id.btnAddWordLayout).visibility = View.VISIBLE }
private fun hideAddWordButton() {
activity!!.findViewById<ImageButton>(R.id.btnAddWord).visibility = View.GONE }
activity!!.findViewById<FrameLayout>(R.id.btnAddWordLayout).visibility = View.GONE }
private fun hideClearButton() { btnClear.visibility = View.GONE }
private fun showClearButton() { btnClear.visibility = View.VISIBLE }
private fun addWord() {
//todo get word data from edit texts and save it
(activity as MainActivity).hideKeyboard(activity as MainActivity)
val word = etWord.text.toString()
val translation = etTranslation.text.toString()
val vocabularyId = (activity as MainActivity).vocabularyId
......
......@@ -41,6 +41,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fragment_new_word" />
<FrameLayout
android:id="@+id/btnAddWordLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:background="@color/colorPrimary"
android:visibility="invisible">
<ImageButton
android:id="@+id/btnAddWord"
android:layout_width="wrap_content"
......@@ -49,11 +57,11 @@
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:visibility="invisible"
android:layout_gravity="end"
app:srcCompat="@drawable/ic_done_icon" />
</FrameLayout>
</android.support.constraint.ConstraintLayout>
<android.support.design.widget.NavigationView
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment