欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android?掃碼槍輸入時(shí)屏蔽軟鍵盤和頂部狀態(tài)欄的解決方案

 更新時(shí)間:2024年10月12日 08:53:30   作者:huelse  
在Android設(shè)備上,使用掃碼槍時(shí)常遇到軟鍵盤和頂部狀態(tài)欄顯示問(wèn)題,本文介紹了在Android 7.1.2版本上,如何通過(guò)設(shè)置inputType為none屏蔽軟鍵盤,以及通過(guò)hideStatusBar和NoActionBar方法隱藏頂部狀態(tài)欄,以優(yōu)化掃碼槍使用界面,這些方法有助于提升使用掃碼槍場(chǎng)景的用戶體驗(yàn)

這是個(gè)掃碼槍回車輸入掃碼內(nèi)容的界面,常用于收銀收款等場(chǎng)景
前期踩了很多坑,網(wǎng)上的資料也因?yàn)?Android 歷史版本不同有各種兼容問(wèn)題,最后總結(jié)了下
在無(wú)霸屏設(shè)置的 android 設(shè)備上使用如下方案可有效避免界面彈出軟鍵盤和顯示頂部狀態(tài)欄問(wèn)題,環(huán)境為 Android 7.1.2
屏蔽軟鍵盤:自動(dòng)聚焦 的 inputType 設(shè)置為 none
隱藏頂部狀態(tài):方案一 hideStatusBar 必須在 setContentView 之前,方案二在 styles 中設(shè)置 NoActionBar 具體可自行搜索

  • AndroidManifest.xml
<activity
    android:name=".MyActivity"
    android:windowSoftInputMode="stateHidden"
    android:exported="false" />
  • activity_my.xml
<EditText
    android:id="@+id/scanInput"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:focusedByDefault="true"
    android:importantForAutofill="no"
    android:inputType="none" />
  • MyActivity.kt
class MyActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMyBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMyBinding.inflate(layoutInflater)
        hideStatusBar()
        setContentView(binding.root)
        hideSoftKeyboard()
    }
    override fun onResume() {
        super.onResume()
        hideSoftKeyboard()
        hideActionBar()
    }
    private fun hideSoftKeyboard() {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
        this.currentFocus?.let { view ->
            val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
            imm?.hideSoftInputFromWindow(view.windowToken, InputMethodManager.RESULT_HIDDEN)
        }
    }
    private fun hideStatusBar() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
    }
    private fun hideActionBar() {
        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
        actionBar?.hide()
    }
}

到此這篇關(guān)于Android 掃碼槍輸入時(shí)屏蔽軟鍵盤和頂部狀態(tài)欄的文章就介紹到這了,更多相關(guān)Android屏蔽軟鍵盤和頂部狀態(tài)欄內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論