android 軟鍵盤的POPUP布局的問題解決
我正在開發(fā)一個(gè)軟鍵盤,做得很好,但是我不知道如何自定義一個(gè)長(zhǎng)按鍵的彈出窗口.
我的鍵盤視圖:
<?xml version="1.0" encoding="UTF-8"?> <android.inputmethodservice.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/keyboard" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:keyPreviewLayout="@layout/preview" android:keyBackground="@drawable/key_selector" android:shadowRadius="0.0" android:keyTextColor="#000000" />
我的鍵盤布局:
<?xml version="1.0" encoding="utf-8"?> <Keyboard xmlns:android="http://schemas.android.com/apk/res/android" android:keyWidth="10%p" android:keyHeight="10%p"> <Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p"> <Key android:codes="113" android:keyLabel="q" /> <Key android:codes="119" android:keyLabel="w" /> <Key android:codes="101" android:keyLabel="e" /> <Key android:codes="114" android:keyLabel="r" /> <Key android:codes="116" android:keyLabel="t" /> <Key android:codes="121" android:keyLabel="y" android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="yýÿ"/> <Key android:codes="117" android:keyLabel="u" android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="uúùũûü"/> <Key android:codes="105" android:keyLabel="i" android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="iíìĩîï"/> <Key android:codes="111" android:keyLabel="o" android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="oóò ôö" /> <Key android:codes="112" android:keyLabel="p" /> </Row> <Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p"> <Key android:codes="97" android:keyLabel="a" android:keyEdgeFlags="left" android:horizontalGap="5%p" android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="aáà âä"/> <Key android:codes="115" android:keyLabel="s" /> <Key android:codes="100" android:keyLabel="d" /> <Key android:codes="102" android:keyLabel="f" /> <Key android:codes="103" android:keyLabel="g" /> <Key android:codes="104" android:keyLabel="h" /> <Key android:codes="106" android:keyLabel="j" /> <Key android:codes="107" android:keyLabel="k" /> <Key android:codes="108" android:keyLabel="l" /> </Row> <Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p"> <Key android:codes="3" android:keyIcon="@drawable/keyboard_shift_off" android:keyHeight="7.6%p" android:keyWidth="13.7%p"/> <Key android:codes="122" android:keyLabel="z" android:horizontalGap="1%p"/> <Key android:codes="120" android:keyLabel="x" /> <Key android:codes="99" android:keyLabel="c" android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="cç"/> <Key android:codes="118" android:keyLabel="v" /> <Key android:codes="98" android:keyLabel="b" /> <Key android:codes="110" android:keyLabel="n" android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="nñ"/> <Key android:codes="109" android:keyLabel="m" /> <Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete_dim" android:keyHeight="7.6%p" android:keyWidth="13.7%p" android:horizontalGap="1%p"/> </Row> <Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p"> <Key android:codes="-16" android:keyIcon="@drawable/keyboard_symbol" android:keyHeight="7.6%p" android:keyWidth="18.7%p"/> <Key android:codes="44" android:keyLabel="," android:horizontalGap="1%p"/> <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_feedback_space" android:keyWidth="40%p"/> <Key android:codes="46" android:keyLabel="."/> <Key android:codes="-3" android:keyIcon="@drawable/keyboard_go" android:keyHeight="7.6%p" android:keyWidth="18.5%p" android:horizontalGap="1%p"/> </Row>
鍵盤彈出XML:
<?xml version="1.0" encoding="utf-8"?> <Keyboard xmlns:android="http://schemas.android.com/apk/res/android" android:keyWidth="10%p" android:keyHeight="10%p"> </Keyboard>
我嘗試將keyBackground和背景屬性放在任何地方,但不成功.我試圖把:
android:popupLayout="@layout/keyboard"
…在keyboardView上得到nullpointer,也許我在該參數(shù)中輸入了錯(cuò)誤的XML?
在我放在這里的鍵盤彈出式XML中:
android:popupKeyboard="@xml/keyboard_popup"
我可以改變布局的大小,按鍵大小,鍵間距等等,但不能改變顏色或背景.
關(guān)鍵預(yù)覽也做得很好,我把它放在keyboardView上:
android:keyPreviewLayout="@layout/preview"
…它的工作原理我認(rèn)為彈出窗口應(yīng)該是一樣的,但不是這樣.
如何自定義出現(xiàn)長(zhǎng)按鍵的彈出式窗口?
那么這不是我正在尋找的,而是解決了這個(gè)問題.
我自己創(chuàng)建了鍵盤視圖,并彈出一個(gè)彈出窗口來顯示一個(gè)鍵長(zhǎng)時(shí)間按下.
public class MyKeyboardView extends KeyboardView{
@Override
protected boolean onLongPress(final Key popupKey) {
final View custom = LayoutInflater.from(context)
.inflate(R.layout.popup_layout, new FrameLayout(context));
popup = new PopupWindow(context);
popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
popup.showAtLocation(this, Gravity.NO_GRAVITY, popupKey.x, popupKey.y-50);
}
}
這樣,您可以在xml中以任何方式自定義彈出窗口.
但是這不是正確的答案,如果你知道一個(gè)更好的方法來回答這個(gè)問題.
http://stackoverflow.com/questions/34799775/soft-keyboards-popup-layout
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 騰訊、百度、華為、搜狗和滴滴Android面試題匯總
- Android 面試題匯總
- Android工程師面試題大全
- Android招聘面試題解答
- Android解決ScrollView下嵌套ListView和GridView中內(nèi)容顯示不全的問題
- Android開發(fā)解決popupWindow重疊報(bào)錯(cuò)問題
- Android微信分享大圖遇到的問題的解決方法
- android: targetSdkVersion升級(jí)中Only fullscreen activities can request orientation問題的解決方法
- 2021最新Android筆試題總結(jié)美團(tuán)Android崗職能要求
相關(guān)文章
Android與JS之間跨平臺(tái)異步調(diào)用實(shí)例詳解
這篇文章主要介紹了Android與JS之間跨平臺(tái)異步調(diào)用實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2016-11-11
Android手機(jī)開發(fā) 使用線性布局和相對(duì)布局實(shí)現(xiàn)Button垂直水平居中
本文主要結(jié)合自己的理解分別對(duì)使用LinearLayout和RelativeLayout兩種方式實(shí)現(xiàn)居中做了總結(jié),希望對(duì)大家有所幫助。2016-05-05
Android的App啟動(dòng)時(shí)白屏的問題解決辦法
這篇文章主要介紹了Android的App啟動(dòng)時(shí)白屏的問題相關(guān)資料,在App啟動(dòng)的第一次的時(shí)候白屏?xí)欢螘r(shí)間,這里提供了解決辦法,需要的朋友可以參考下2017-08-08
android的ListView點(diǎn)擊item使item展開的做法的實(shí)現(xiàn)代碼
這篇文章主要介紹了android的ListView點(diǎn)擊item使item展開的做法的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-12-12
Android中WebView實(shí)現(xiàn)點(diǎn)擊超鏈接啟動(dòng)QQ的方法
這篇文章主要給大家介紹了在Android中WebView如何實(shí)現(xiàn)點(diǎn)擊超鏈接啟動(dòng)QQ的方法,文中給出了詳細(xì)的示例代碼,相信對(duì)大家的學(xué)習(xí)或者工作具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。2017-04-04
Kotlin RadioGroup與ViewPager實(shí)現(xiàn)底層分頁按鈕方法
安卓的控件是挺多的,沒有辦法一個(gè)一個(gè)的來說明,我們挑出了一些重點(diǎn)的控件,組成一些常見的布局,這樣以后在遇到相同功能的界面時(shí),就會(huì)有自己的思路,或者進(jìn)行復(fù)用2022-12-12

