我正在为 Android 开发一个自定义键盘,我遇到了一个问题,键盘似乎在右边留下了一条白线/空格,而不是填充父 View ......(不要请注 Intent 标,它现在只是占位符图形)
下面你可以看到我的布局...
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="14%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="60dp"
>
<Row>
<Key android:codes="49" android:keyIcon="@drawable/rsz_emoji" android:horizontalGap="1%p" android:keyEdgeFlags="left"/>
<Key android:codes="50" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="51" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="52" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="53" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="54" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="48" android:keyIcon="@drawable/rsz_emoji" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="113" android:keyIcon="@drawable/rsz_emoji" android:horizontalGap="8%p" android:keyEdgeFlags="left"/>
<Key android:codes="114" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="116" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="121" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="111" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="112" android:keyIcon="@drawable/rsz_emoji" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="1" android:keyIcon="@drawable/rsz_emoji" android:keyWidth="28%p" android:horizontalGap="8%p" android:keyEdgeFlags="left"/>
<Key android:codes="46" android:keyIcon="@drawable/rsz_emoji" android:keyWidth="28%p"/>
<Key android:codes="58" android:keyIcon="@drawable/rsz_emoji" android:keyWidth="28%p" android:keyEdgeFlags="right"/>
</Row>
<Row android:rowEdgeFlags="bottom">
<Key android:codes="44" android:keyIcon="@drawable/globe" android:horizontalGap="8%p" android:keyEdgeFlags="left"/>
<Key android:codes="47" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="32" android:keyIcon="@drawable/rsz_emoji" android:keyWidth="28%p"/>
<Key android:codes="1" android:keyIcon="@drawable/rsz_emoji"/>
<Key android:codes="-5" android:keyIcon="@drawable/backspace" android:keyEdgeFlags="right"/>
</Row>
</Keyboard>
据我所知,这是 1%p 的问题...但我有点不确定如何在不弄乱对齐方式的情况下填充它...例如将第一行的间距更改为 2 会修复它,但会弄乱对齐。
根据要求为您添加了额外的代码...
我的类扩展 InputMethodService:
private KeyboardView kv;
private Keyboard keyboard;
@Override
public View onCreateInputView() {
kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.custom_keyboard);
kv.setPreviewEnabled(false);
kv.setKeyboard(keyboard);
kv.setOnKeyboardActionListener(this);
return kv;
}
@Override
public void onPress(int primaryCode) {
}
@Override
public void onRelease(int primaryCode) {
}
@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
if (primaryCode == Keyboard.KEYCODE_DELETE) {
ic.deleteSurroundingText(1, 0);
} else {
Drawable mDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.rsz_emoji, null);
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, "Emoticon", null);
Uri fileUri = Uri.parse(path);
Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
picMessageIntent.setPackage("com.android.mms");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
picMessageIntent.setType("image/png");
picMessageIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(picMessageIntent);
}
}
@Override
public void onText(CharSequence text) {
}
@Override
public void swipeLeft() {
}
@Override
public void swipeRight() {
}
@Override
public void swipeDown() {
}
@Override
public void swipeUp() {
}
我的键盘.xml
<?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"
/>
样式.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="CENSORED" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Declares the input method service -->
<service android:name=".CENSORED"
android:label="@string/keyboard_name"
android:permission="android.permission.BIND_INPUT_METHOD">
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data android:name="android.view.im"
android:resource="@xml/method" />
</service>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
最佳答案
我无法重现错误,我提供了一个屏幕截图,其中包含一个浅色背景应用程序和我所有的相关代码。在没有看到整个项目和目录的情况下,我不确定你到底哪里出错了,所以我发布了相关的 xml。还有一个服务类,我没有包括在内(因为您显然可以使用它)。
<Keyboard>代码在一个名为 qwerty.xml 的文件中在 resources/xml 文件夹中,有一个名为 method.xml 的文件:
我在 qwerty.xml 中使用了所有键盘尺寸,除了我替换了图像。
method.xml
<?xml version="1.0" encoding="utf-8"?>
<input-method xmlns:android="http://schemas.android.com/apk/res/android">
<subtype
android:label="@string/subtype_en_US"
android:imeSubtypeLocale="en_US"
android:imeSubtypeMode="keyboard" />
</input-method>
两个布局文件:
keyboard.xml
<?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"
/>
preview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff00"
android:gravity="center"
android:textSize="30sp
android:textStyle="bold">
</TextView>
样式:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
在 list 中,在应用程序中:
<service
android:name=".SimpleIME"
android:label="@string/simple_ime"
android:permission="android.permission.BIND_INPUT_METHOD"
>
<meta-data
android:name="android.view.im"
android:resource="@xml/method"/>
<intent-filter>
<action android:name="android.view.InputMethod"/>
</intent-filter>
</service>
此处的链接也逐步执行了这段代码:
http://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615
编辑1
在评论中讨论后,我建议检查您的背景样式,因为键盘窗口可能会显示默认背景颜色的问题/更改。此答案中详细解决了这个问题 https://stackoverflow.com/a/33052648/3956566 .我不会重申细节,因为链接不太可能失效,因为它是一个被点赞的 SO 帖子。
编辑2
Ok 添加输入法服务的区别:
@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection();
switch(primaryCode){
case Keyboard.KEYCODE_DELETE :
ic.deleteSurroundingText(1, 0);
break;
case Keyboard.KEYCODE_SHIFT:
caps = !caps;
keyboard.setShifted(caps);
kv.invalidateAllKeys();
break;
case Keyboard.KEYCODE_DONE:
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
break;
default:
char code = (char)primaryCode;
if(Character.isLetter(code) && caps){
code = Character.toUpperCase(code);
}
ic.commitText(String.valueOf(code),1);
}
}
编辑3
创建一个空白项目,键盘没有任何 Activity ,以将其作为单独的应用程序进行测试和运行。您正在使用 android:theme="@style/AppTheme.NoActionBar"在您的启动器 Activity 中,背景不透明度和您的窗口/ View 可能存在问题。
关于Android自定义键盘布局在侧面留下白色边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33610139/
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我正在尝试在Ruby中制作一个cli应用程序,它接受一个给定的数组,然后将其显示为一个列表,我可以使用箭头键浏览它。我觉得我已经在Ruby中看到一个库已经这样做了,但我记不起它的名字了。我正在尝试对soundcloud2000中的代码进行逆向工程做类似的事情,但他的代码与SoundcloudAPI的使用紧密耦合。我知道cursesgem,我正在考虑更抽象的东西。广告有没有人见过可以做到这一点的库或一些概念证明的Ruby代码可以做到这一点? 最佳答案 我不知道这是否是您正在寻找的,但也许您可以使用我的想法。由于我没有关于您要完成的工作
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano
我使用Ember作为我的前端和GrapeAPI来为我的API提供服务。前端发送类似:{"service"=>{"name"=>"Name","duration"=>"30","user"=>nil,"organization"=>"org","category"=>nil,"description"=>"description","disabled"=>true,"color"=>nil,"availabilities"=>[{"day"=>"Saturday","enabled"=>false,"timeSlots"=>[{"startAt"=>"09:00AM","endAt"=>
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我正在阅读一本关于Ruby的书,作者在编写类初始化定义时使用的形式与他在本书前几节中使用的形式略有不同。它看起来像这样:classTicketattr_accessor:venue,:datedefinitialize(venue,date)self.venue=venueself.date=dateendend在本书的前几节中,它的定义如下:classTicketattr_accessor:venue,:datedefinitialize(venue,date)@venue=venue@date=dateendend在第一个示例中使用setter方法与在第二个示例中使用实例变量之间是