我正在显示一个文本输入对话框,如果没有打开硬键盘,我想自动显示软键盘。为了让它在我的三星 Galaxy Tab 上显示,我不得不使用 SHOW_FORCED 标志,SHOW_IMPLICIT 标志不起作用。另外,在关闭对话框时,如果我强制显示键盘,我想关闭键盘。但是,我在下面使用的代码不会关闭 Galaxy Tab 上的键盘;我认为这是因为我使用了 Explicit 标志来显示。
/* from the dialog constructor*/
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(mEditText);
//only display if there is no hard keyboard out
Configuration config = getResources().getConfiguration();
if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES)
{
mForcedKeyboardDisplay = true;
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
/* from the onDismiss() method*/
//if we previously forced keyboard display, force it to close
if (mForcedKeyboardDisplay)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(mEditText);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
//this doesn't work either
//imm.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
//nor does this …Run Code Online (Sandbox Code Playgroud) 在该函数中pickSuggestionManually(int index)
,注释文档说明如下:
// If we were generating candidate suggestions for the current
// text, we would commit one of them here. But for this sample,
// we will just commit the current text.
commitTyped(getCurrentInputConnection());
Run Code Online (Sandbox Code Playgroud)
现在,如何提交一个候选建议?
有人可以帮忙吗?
问候,Sayantan
我正在使用我的应用程序中的编辑文本字段.当我点击它时出现软键盘.但是当我点击"完成"按钮(在软键盘上)时,它应该消失但它不会消失.我将输入类型设置为布局文件中的文本.我想按下按钮时隐藏软键盘.请帮忙.谢谢.
这是我的代码.
public class locupdate extends MapActivity implements OnDoubleTapListener{
GeoPoint p,geoPoint;
MapView SearchMap;
List<Overlay> list;
MapController map_controller;
LocationManager locationManager;
Location location,update_location ;
MyLocationOverlay me;
Button go_btn,done;
String city;
int cid;
Double lat_update,lng_update;
EditText location_entered;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.bingmapupdate);
go_btn=new Button(getApplicationContext());
go_btn=(Button)findViewById(R.id.go_button);
location_entered=(EditText)findViewById(R.id.enterLocationforSearch);
location_entered.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
location_entered.setText("");
}
});
done=new Button(getApplicationContext());
done=(Button)findViewById(R.id.button_locationUpdateDone);
done.setEnabled(false);
done.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor=preferences.edit();
String memberid=preferences.getString("unique_userName", null);
String …Run Code Online (Sandbox Code Playgroud) 我在 android 中有一个自定义虚拟键盘,单击按钮时会出现该键盘。
如果我keyPreviewLayout在语句中设置 aandroid:keyPreviewLayout="@layout/mykeypreviewlayout"
并res/layout/mykeypreviewlayout.xml在运行时包含一些布局语句,当触摸自定义软键盘上的某个键时,应用程序会崩溃。
以下是代码片段: 以下来自主 xml 文件。
<LinearLayout android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_width="wrap_content">
<android.inputmethodservice.KeyboardView
android:id="@+id/keyboardView" android:visibility="gone"
android:focusable="true" android:focusableInTouchMode="true"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:keyPreviewLayout="@layout/mykeypreviewlayout"
android:layout_weight="0" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是来自'res/layout/mykeypreviewlayout.xml的xml代码
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:textColor="@color/black"> </TextView>
Run Code Online (Sandbox Code Playgroud)
如果从上面的 KeyboardView 布局中删除设置 keyPreviewLayout attr 的行,则应用程序正常运行。但是,当按键反馈预览窗口在按下的字符上方弹出时,该窗口是空白的,并且没有显示任何字符——只出现一个带有白色背景的小矩形字符大小的弹出窗口。
如果我添加设置 keyPreviewLayout 的行,那么当在软键盘上触摸某个键时应用程序会崩溃。
这是 logcat 的堆栈跟踪的转储(相关的前几行)显示崩溃发生在 KeyboardView.java 内
04-17 07:41:47.346: E/AndroidRuntime(11901): FATAL EXCEPTION: main
04-17 07:41:47.346: E/AndroidRuntime(11901): java.lang.NullPointerException
04-17 07:41:47.346: E/AndroidRuntime(11901): at android.inputmethodservice.KeyboardView.showKey(KeyboardView.java:918)
04-17 07:41:47.346: E/AndroidRuntime(11901): at android.inputmethodservice.KeyboardView.access$100(KeyboardView.java:65)
04-17 07:41:47.346: E/AndroidRuntime(11901): at android.inputmethodservice.KeyboardView$1.handleMessage(KeyboardView.java:251)
04-17 07:41:47.346: E/AndroidRuntime(11901): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 …Run Code Online (Sandbox Code Playgroud) 当我ScrollView在我的文件中使用 a 时,如何隐藏软键盘输入LinearLayout?
我试图在我的活动类中实现以下内容,尽管这些解决方案都没有产生预期的结果:
(1)
@Override
public boolean onTouchEvent(MotionEvent event)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
return true;
}
Run Code Online (Sandbox Code Playgroud)
(2)
@Override
public boolean onTouchEvent(MotionEvent event)
{
ScrollView myScrollView = (ScrollView) findViewById(R.id.scrollview); //of course scrollview was id in layout then
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
return true;
}
Run Code Online (Sandbox Code Playgroud)
(3)
与#2 相同,但用LinearLayout代替ScrollView。
这三种解决方案都不适合我。
我注意到的一件事是,当我ScrollView从layout.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:keyBackground="@drawable/key_background"
android:background="@color/keyboard_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:keyPreviewLayout="@layout/preview" />
Run Code Online (Sandbox Code Playgroud)
key_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Bottom 2dp Shadow -->
<item android:top="4dp"
android:left="2dp"
android:right="2dp">
<shape android:shape="rectangle" >
<solid android:color="@color/key_shadow" />
<corners android:radius="4dp"/>
</shape>
</item>
<!-- White Top color -->
<item android:bottom="4px"
android:top="4dp"
android:left="2dp"
android:right="2dp">
<shape android:shape="rectangle" >
<solid android:color="@color/white" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud) 我正在学习如何为Android设备创建自定义键盘.我使用的是Android Studio 2.1.2.程序中没有任何活动,因为您必须在语言和输入设置中激活键盘.
当我运行该程序时,我收到此错误:"无法识别启动活动:启动活动时未找到默认活动错误"
我在网站上发布但没有得到回应.我按照教程一步一步地查看了几天.我是Android Studio和Android应用程序的新手,想知道是否有人知道如何帮助我.
这是我关注的网站的链接:http://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615
android soft-keyboard android-softkeyboard android-studio custom-keyboard
我有几个EditText在RecyclerView那里面是一个BottomSheetDialog。我现在的问题是,当BottomSheetDialog屏幕上显示,我轻按例如7 EditText中RecyclerView。软键盘出现并覆盖EditText,所以我看不到我输入的内容。但是如果我BottomSheetDialog向上拖动一点,EditText即使我点击EditText屏幕上的最后一个,也不会被软键盘覆盖。RecyclerView在这种情况下肯定会调整大小,但如果我不BottonSheetDialog向上拖动,则不会调整大小。知道为什么吗?我该如何解决这个问题?
主程序
class VH extends RecyclerView.ViewHolder {
public VH(View itemView) {
super(itemView);
}
}
private void test() {
BSTest bsTest = new BSTest(this);
bsTest.setContentView(R.layout.bottomsheet_test);
RecyclerView rv = (RecyclerView) bsTest.findViewById(R.id.recyclerView);
rv.setLayoutManager(new LinearLayoutManager(this));
rv.setAdapter(new RecyclerView.Adapter() {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new VH(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_edittext, parent, false));
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) …Run Code Online (Sandbox Code Playgroud) PasscodeView我的对话框片段布局中有一个自定义视图。
密码视图.java:
public class PasscodeView extends ViewGroup {
EditText mEditText;
int mDigitCount;
private int mDigitWidth;
private int mDigitRadius;
private int mOuterStrokeWidth;
private int mInnerStrokeWidth;
private int mDigitInnerRadius;
private int mDigitSpacing;
private int mDigitElevation;
private int mControlColor;
private int mHighlightedColor;
private int mInnerColor;
private int mInnerBorderColor;
private OnFocusChangeListener mOnFocusChangeListener;
private PasscodeEntryListener mPasscodeEntryListener;
public PasscodeView(Context context) {
this(context, null);
}
public PasscodeView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public PasscodeView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); …Run Code Online (Sandbox Code Playgroud) keyboard android android-custom-view android-softkeyboard android-dialogfragment
我有一个使用“adjustPan”作为其调整大小配置的活动,并且我需要计算键盘高度而不使用“adjustResize”,因为我需要将一些视图保留为全屏(这意味着它们应该保持在原来的位置,键盘应该隐藏它们),并将视图放置在键盘正上方。我们的应用程序有一个消息按钮,我通过单击按钮打开键盘。当发生这种情况时,我使用 OnGlobalLayoutListener 并使用“getWindowVisibleDisplayFrame”方法来获取键盘的高度。这是它的一些代码:
private void message()
{
InputMethodManager methodManager =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (methodManager != null && !isKeyboardOpen)
{
methodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
if (bottomCoordinate == 0)
{
RelativeLayout layout = findViewById(getFullScreenContainerId());
layout.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
layout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Rect r = new Rect();
layout.getWindowVisibleDisplayFrame(r);
bottomCoordinate = r.bottom - r.top;
translateMessageView(bottomCoordinate);
}
});
}
else
translateMessageView(bottomCoordinate);
isKeyboardOpen = true;
}
}
Run Code Online (Sandbox Code Playgroud)
“translateMessageView”基本上将视图的 Y 坐标设置为“bottomCooperative - view.getHeight()”。在软键盘应用程序的自动更正部分变得可见之前,这种方法一直有效。显然,“getWindowVisibleDisplayFrame”方法似乎没有添加视图的自动更正部分,或者当软键盘的自动更正部分显示时,不会调用“onGlobalLayout”方法,并且定位的视图保留在其下方,这使其半可见。我需要能够再次调整它的位置,那么我该怎么办?正确的做法是什么?任何建议都很有价值,谢谢。