This is a code scanning gun back to enter the code content of the interface, commonly used in cash registers and other scenarios
I stepped on a lot of potholes in the early stage, and the online information also has various compatibility problems because of the different versions of Android history, and finally summarized the
The following scheme can be used on android devices with no screen-blocking settings to effectively avoid the soft keyboard popup and the real top status bar issue, in Android 7.1.2 environment
Shielded Soft Keyboard: Auto Focus
Hide the top state look: Option 1hideStatusBar
must be insetContentView
Previously, Option 2 set theNoActionBar
Search for yourself
<activity
android:name=".MyActivity"
android:windowSoftInputMode="stateHidden"
android:exported="false" />
- activity_my.xml
<EditText
android:
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:focusedByDefault="true"
android:importantForAutofill="no"
android:inputType="none" />
class MyActivity : AppCompatActivity() {
private lateinit var binding: ActivityMyBinding
override fun onCreate(savedInstanceState: Bundle?) {
(savedInstanceState)
binding = (layoutInflater)
hideStatusBar()
setContentView()
hideSoftKeyboard()
}
override fun onResume() {
()
hideSoftKeyboard()
hideActionBar()
}
private fun hideSoftKeyboard() {
(.SOFT_INPUT_STATE_HIDDEN)
?.let { view ->
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
imm?.hideSoftInputFromWindow(, InputMethodManager.RESULT_HIDDEN)
}
}
private fun hideStatusBar() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
(
.FLAG_FULLSCREEN,
.FLAG_FULLSCREEN
)
}
private fun hideActionBar() {
= View.SYSTEM_UI_FLAG_FULLSCREEN
actionBar?.hide()
}
}
If you have any questions or suggestions, please feel free to discuss and correct them in the comments section!