为什么默认情况下EditTexts在服务类中不显示键盘?我尝试了许多不同的方法,但没有一个能奏效。也没有崩溃。我对为什么如此困难感到困惑。它显示了何时专注于此,但没有任何结果。有人可以帮帮我吗。如果您想要更多代码,请不要犹豫。这是一个代码段:
final EditText opHexEdit = new EditText(this);
RelativeLayout.LayoutParams opHexEditParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opHexEdit.setLayoutParams(opHexEditParam);
opHexEdit.setHint("Ex: 01 00 A0 E3 1E FF 2F E1");
LL3.addView(opHexEdit);
更多代码。由于饥饿的android leechers的存在,这就是我要展示的全部内容:
final RelativeLayout collapsedView = new RelativeLayout(this);
RelativeLayout.LayoutParams collapsedViewParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
collapsedView.setLayoutParams(collapsedViewParam);
collapsedView.setVisibility(View.VISIBLE);
menuHolder.addView(collapsedView);
final RelativeLayout expandedView = new RelativeLayout(this);
RelativeLayout.LayoutParams expandedViewParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
expandedView.setLayoutParams(expandedViewParam);
expandedView.setVisibility(View.GONE);
expandedView.setBackgroundColor(Color.parseColor("#FF0000"));
menuHolder.addView(expandedView);
final ImageView pmtIcon = new ImageView(this);
ViewGroup.LayoutParams pmtIconParam = new ViewGroup.LayoutParams(175, 175);
pmtIcon.setLayoutParams(pmtIconParam);
collapsedView.addView(pmtIcon);
File myFile = new File(Environment.getExternalStorageDirectory().getPath() + "/pmt/images/pmt_icon_round.png");
Bitmap bmp = BitmapFactory.decodeFile(myFile.getAbsolutePath());
pmtIcon.setImageBitmap(bmp);
final LinearLayout LL = new LinearLayout(this);
LinearLayout.LayoutParams LLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LL.setLayoutParams(LLP);
LL.setOrientation(LinearLayout.VERTICAL);
LL.setBackgroundColor(Color.parseColor("#FFFFFF"));
expandedView.addView(LL);
final LinearLayout LL1 = new LinearLayout(this);
LinearLayout.LayoutParams LL1P = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LL1.setLayoutParams(LL1P);
LL1.setOrientation(LinearLayout.HORIZONTAL);
LL.addView(LL1);
final TextView opBlankSpaces = new TextView(this);
RelativeLayout.LayoutParams opBlankSpacesParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opBlankSpaces.setLayoutParams(opBlankSpacesParam);
opBlankSpaces.setText(" ");
opBlankSpaces.setTextSize(26);
LL1.addView(opBlankSpaces);
final TextView opTitle = new TextView(this);
RelativeLayout.LayoutParams opTitleParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opTitle.setLayoutParams(opTitleParam);
opTitle.setTextColor(Color.parseColor("#000000"));
opTitle.setTextSize(38);
SpannableString underline = new SpannableString(" Live Offset Patcher ");
underline.setSpan(new UnderlineSpan(), 0, underline.length(), 0);
opTitle.setText(underline);
LL1.addView(opTitle);
final TextView opBlankSpaces1 = new TextView(this);
RelativeLayout.LayoutParams opBlankSpaces1Param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opBlankSpaces1.setLayoutParams(opBlankSpaces1Param);
opBlankSpaces1.setText(" ");
opBlankSpaces1.setTextSize(26);
LL1.addView(opBlankSpaces1);
final TextView opBlankSpace = new TextView(this);
RelativeLayout.LayoutParams opBlankSpaceParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opBlankSpace.setLayoutParams(opBlankSpaceParam);
opBlankSpace.setText(" ");
opBlankSpace.setTextColor(Color.parseColor("#000000"));
opBlankSpace.setTextSize(12);
LL.addView(opBlankSpace);
final LinearLayout LL2 = new LinearLayout(this);
LinearLayout.LayoutParams LL2P = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LL2.setLayoutParams(LL2P);
LL2.setOrientation(LinearLayout.HORIZONTAL);
LL.addView(LL2);
final TextView opOffsetText = new TextView(this);
RelativeLayout.LayoutParams opOffsetTextParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opOffsetText.setLayoutParams(opOffsetTextParam);
opOffsetText.setText(" Offset: ");
opOffsetText.setTextSize(17);
opOffsetText.setTextColor(Color.parseColor("#000000"));
LL2.addView(opOffsetText);
final EditText opOffsetEdit = new EditText(this);
RelativeLayout.LayoutParams opOffsetEditParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opOffsetEdit.setLayoutParams(opOffsetEditParam);
opOffsetEdit.setHint("Ex: 0x002864AC");
LL2.addView(opOffsetEdit);
final LinearLayout LL3 = new LinearLayout(this);
LinearLayout.LayoutParams LL3P = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LL3.setLayoutParams(LL3P);
LL3.setOrientation(LinearLayout.HORIZONTAL);
LL.addView(LL3);
final TextView opHexText = new TextView(this);
RelativeLayout.LayoutParams opHexTextParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opHexText.setLayoutParams(opHexTextParam);
opHexText.setText(" Hex: ");
opHexText.setTextSize(17);
opHexText.setTextColor(Color.parseColor("#000000"));
LL3.addView(opHexText);
final EditText opHexEdit = new EditText(this);
RelativeLayout.LayoutParams opHexEditParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opHexEdit.setLayoutParams(opHexEditParam);
opHexEdit.setHint("Ex: 01 00 A0 E3 1E FF 2F E1");
LL3.addView(opHexEdit);
opHexEdit.requestFocus();
final LinearLayout LL5 = new LinearLayout(this);
LinearLayout.LayoutParams LL5P = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LL5.setLayoutParams(LL5P);
LL5.setOrientation(LinearLayout.HORIZONTAL);
LL.addView(LL5);
final TextView opLibText = new TextView(this);
RelativeLayout.LayoutParams opLibTextParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opLibText.setLayoutParams(opLibTextParam);
opLibText.setText(" Lib: ");
opLibText.setTextSize(17);
opLibText.setTextColor(Color.parseColor("#000000"));
LL5.addView(opLibText);
final EditText opLibEdit = new EditText(this);
RelativeLayout.LayoutParams opLibEditParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opLibEdit.setLayoutParams(opLibEditParam);
opLibEdit.setHint("Ex: libil2cpp");
LL5.addView(opLibEdit);
final TextView opBlankSpace1 = new TextView(this);
RelativeLayout.LayoutParams opBlankSpace1Param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opBlankSpace1.setLayoutParams(opBlankSpace1Param);
opBlankSpace1.setText(" ");
opBlankSpace1.setTextColor(Color.parseColor("#000000"));
opBlankSpace1.setTextSize(13);
LL.addView(opBlankSpace1);
final LinearLayout LL4 = new LinearLayout(this);
LinearLayout.LayoutParams LL4P = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LL4.setLayoutParams(LL4P);
LL4.setOrientation(LinearLayout.HORIZONTAL);
LL.addView(LL4);
final TextView opBlankSpaces2 = new TextView(this);
RelativeLayout.LayoutParams opBlankSpaces2Param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opBlankSpaces2.setLayoutParams(opBlankSpaces2Param);
opBlankSpaces2.setText(" ");
opBlankSpaces2.setTextColor(Color.parseColor("#000000"));
LL4.addView(opBlankSpaces2);
final Button sendItButton = new Button(this);
RelativeLayout.LayoutParams sendItButtonParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
sendItButton.setLayoutParams(sendItButtonParam);
sendItButton.setText(" Modify ");
sendItButton.setTextSize(17);
sendItButton.setTextColor(Color.parseColor("#000000"));
sendItButton.setBackgroundColor(Color.parseColor("#E0E0E0"));
LL4.addView(sendItButton);
sendItButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
offset = opOffsetEdit.getText().toString();
Toast.makeText(MenuActivity.this, "Offset Patched: " + offset, Toast.LENGTH_SHORT).show();
}
});
final TextView opBlankSpaces3 = new TextView(this);
RelativeLayout.LayoutParams opBlankSpaces3Param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opBlankSpaces3.setLayoutParams(opBlankSpaces3Param);
opBlankSpaces3.setText(" ");
opBlankSpaces3.setTextColor(Color.parseColor("#000000"));
LL4.addView(opBlankSpaces3);
final Button closeButton = new Button(this);
RelativeLayout.LayoutParams closeButtonParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
closeButton.setLayoutParams(closeButtonParam);
closeButton.setText(" Close ");
closeButton.setTextSize(17);
closeButton.setTextColor(Color.parseColor("#000000"));
closeButton.setBackgroundColor(Color.parseColor("#E0E0E0"));
LL4.addView(closeButton);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
collapsedView.setVisibility(View.VISIBLE);
expandedView.setVisibility(View.GONE);
Toast.makeText(MenuActivity.this, "Offset Patcher Closed", Toast.LENGTH_SHORT).show();
}
});
final TextView opBlankSpace2 = new TextView(this);
RelativeLayout.LayoutParams opBlankSpace2Param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opBlankSpace2.setLayoutParams(opBlankSpace2Param);
opBlankSpace2.setText(" ");
opBlankSpace2.setTextColor(Color.parseColor("#000000"));
opBlankSpace2.setTextSize(18);
LL.addView(opBlankSpace2);
final TextView opCredits = new TextView(this);
RelativeLayout.LayoutParams opCreditsParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opCredits.setLayoutParams(opCreditsParam);
opCredits.setText(" ~ Liquified @Platinmods.com");
opCredits.setTextColor(Color.parseColor("#000000"));
opCredits.setTextSize(18);
LL.addView(opCredits);
final TextView opBlankSpace3 = new TextView(this);
RelativeLayout.LayoutParams opBlankSpace3Param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
opBlankSpace3.setLayoutParams(opBlankSpace3Param);
opBlankSpace3.setText(" ");
opBlankSpace3.setTextColor(Color.parseColor("#000000"));
opBlankSpace3.setTextSize(18);
LL.addView(opBlankSpace3);
expandedViewF = expandedView;
collapsedViewF = collapsedView;
答案 0 :(得分:0)
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
尝试一下。
答案 1 :(得分:0)
overlayParam的第四个参数最初设置为FLAG_NOT_FOCUSABLE。将其更改为FLAG_NOT_TOUCH_MODAL可以解决此问题,但会导致另一个问题。应用只是无法正常工作,但是至少第一个问题(即问题)已经得到解决。
int overlay;
final WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
overlay = 2038;
}
else {
overlay = 2002;
}
final WindowManager.LayoutParams overlayParam = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
overlay,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
overlayParam.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
overlayParam.x = 0;
overlayParam.y = 0;