
- Forum-Beiträge: 669
22.07.2020, 20:16:43 via Website
22.07.2020 20:16:43 via Website
Hallo zusammen
Ich habe eine Klasse von Java in Kotlin umgeschrieben. Diese Klasse öffnet oder schliesst die Tastatur.
package ch.robbisoft.noteapp
import android.app.Activity
import android.view.inputmethod.InputMethodManager
public class KeyBoard
{
public fun show(activity : Activity){
val imm: InputMethodManager = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY) // show
}
public fun hide(activity : Activity){
val imm = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
imm.toggleSoftInput(
InputMethodManager.HIDE_IMPLICIT_ONLY,
0
) // hide
}
public fun toggle(activity : Activity){
val imm = activity.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
if (imm.isActive) {
hide(activity)
} else {
show(activity)
}
}
}
In Java kann ich die Klasse mit folgendem Code aufrufen
KeyBoard.toggle( this )
Wie funktioniert der Aufruf in Kotlin? Auf jeden Fall geht es nicht wie in Java!
Gruss Renato