Android?掃碼槍輸入時屏蔽軟鍵盤和頂部狀態(tài)欄的解決方案
這是個掃碼槍回車輸入掃碼內(nèi)容的界面,常用于收銀收款等場景
前期踩了很多坑,網(wǎng)上的資料也因為 Android 歷史版本不同有各種兼容問題,最后總結(jié)了下
在無霸屏設置的 android 設備上使用如下方案可有效避免界面彈出軟鍵盤和顯示頂部狀態(tài)欄問題,環(huán)境為 Android 7.1.2
屏蔽軟鍵盤:自動聚焦 的 inputType 設置為 none
隱藏頂部狀態(tài):方案一 hideStatusBar 必須在 setContentView 之前,方案二在 styles 中設置 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()
}
}到此這篇關于Android 掃碼槍輸入時屏蔽軟鍵盤和頂部狀態(tài)欄的文章就介紹到這了,更多相關Android屏蔽軟鍵盤和頂部狀態(tài)欄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Android 中clipToPadding 和 clipChildren區(qū)別和作用
這篇文章主要介紹了Android 中clipToPadding 和 clipChildren區(qū)別和作用的相關資料,需要的朋友可以參考下2017-06-06
android中使用react-native設置應用啟動頁過程詳解
這篇文章主要介紹了android中使用react-native設置應用啟動頁過程詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-07-07
Android 藍牙連接 ESC/POS 熱敏打印機打印實例(藍牙連接篇)
這篇文章主要介紹了Android 藍牙連接 ESC/POS 熱敏打印機打印實例(藍牙連接篇),具有一定的參考價值,感興趣的小伙伴們可以參考一下。2017-04-04
Android仿微信清理內(nèi)存圖表動畫(解決surfaceView屏幕閃爍問題)demo實例詳解
本文通過實例代碼給大家講解android仿微信清理內(nèi)存圖表動畫(解決surfaceView屏幕閃爍問題)的相關資料,本文介紹的非常詳細,具有參考借鑒價值,需要的朋友可以參考下2016-09-09
Android應用程序轉(zhuǎn)到后臺并回到前臺判斷方法
這篇文章主要介紹了Android應用程序轉(zhuǎn)到后臺并回到前臺判斷方法的相關資料,需要的朋友可以參考下2016-11-11

