Android?掃碼槍輸入時屏蔽軟鍵盤和頂部狀態(tài)欄的解決方案
這是個掃碼槍回車輸入掃碼內(nèi)容的界面,常用于收銀收款等場景
前期踩了很多坑,網(wǎng)上的資料也因?yàn)?Android 歷史版本不同有各種兼容問題,最后總結(jié)了下
在無霸屏設(shè)置的 android 設(shè)備上使用如下方案可有效避免界面彈出軟鍵盤和顯示頂部狀態(tài)欄問題,環(huán)境為 Android 7.1.2
屏蔽軟鍵盤:自動聚焦 的 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 掃碼槍輸入時屏蔽軟鍵盤和頂部狀態(tài)欄的文章就介紹到這了,更多相關(guān)Android屏蔽軟鍵盤和頂部狀態(tài)欄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android定時器實(shí)現(xiàn)定時執(zhí)行、重復(fù)執(zhí)行、定時重復(fù)執(zhí)行、定次數(shù)執(zhí)行的多種方式
今天小編就為大家分享一篇關(guān)于Android定時器實(shí)現(xiàn)定時執(zhí)行、重復(fù)執(zhí)行、定時重復(fù)執(zhí)行、定次數(shù)執(zhí)行的多種方式,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2018-12-12Android開發(fā)之如何自定義數(shù)字鍵盤詳解
這篇文章主要給大家介紹了關(guān)于Android開發(fā)之如何自定義數(shù)字鍵盤的相關(guān)資料,本文語言是基于kotlin實(shí)現(xiàn)的,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。2017-09-09Android ExpandableListView展開列表控件使用實(shí)例
這篇文章主要介紹了Android ExpandableListView展開列表控件使用實(shí)例,本文實(shí)現(xiàn)了一個類似手機(jī)QQ好友列表的界面效果,需要的朋友可以參考下2014-07-07Android中AlertDialog四種對話框的最科學(xué)編寫用法(實(shí)例代碼)
這篇文章主要介紹了Android中AlertDialog四種對話框的最科學(xué)編寫用法,本文通過代碼講解的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-11-11Android自定義StickinessView粘性滑動效果
這篇文章主要為大家詳細(xì)介紹了Android自定義StickinessView粘性滑動效果的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03實(shí)例講解Android中ViewPager組件的一些進(jìn)階使用技巧
這篇文章主要介紹了Android中ViewPager組件的一些進(jìn)階使用技巧,包括添加標(biāo)題與onPagerChangeListener監(jiān)聽使用等,需要的朋友可以參考下2016-03-03