gpt4 book ai didi

android - 软键盘在android中打不开

转载 作者:行者123 更新时间:2023-11-30 01:16:22 24 4
gpt4 key购买 nike

<分区>

我是 android 的新手并且正在开发一个演示应用程序,因为我有一个 Activity 在屏幕顶部包含一个编辑文本并且想在该 Activity 开始时显示键盘我已经尝试了很多方法但没有这个作品,哪位大佬可以帮我整理一下吗?

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/rl_hdr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#16BBA1"
android:gravity="center_vertical"
android:padding="10dp">

<ImageView
android:id="@+id/iv_back"
android:layout_width="25dp"
android:layout_height="22dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="0dp"
android:src="@drawable/ic_back_white" />

<EditText
android:layout_width="fill_parent"
android:layout_height="40dp"
android:textColorHint="#939393"
android:singleLine="true"
android:layout_centerInParent="true"
android:hint="Search"
android:layout_marginLeft="5dp"
android:padding="5dp"
android:gravity="center_vertical"
android:drawablePadding="5dp"
android:layout_marginRight="5dp"
android:textSize="16dp"

android:imeOptions="actionDone"
android:cursorVisible="true"
android:layout_toRightOf="@+id/iv_back"
android:drawableRight="@drawable/ic_search"
android:background="@drawable/bg_et_actionbar"
android:id="@+id/et_search" />


</RelativeLayout>

<FrameLayout
android:id="@+id/fragmentTimeline"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"

android:layout_marginTop="0dp" />

</LinearLayout>

list .xml

<activity
android:name="one.tusk.stush.SearchPostActivity"
android:label="Back"
android:parentActivityName="one.tusk.stush.activities.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysVisible" >
>
</activity>

SerachPostActivity.java

public class SearchPostActivity extends FragmentActivity implements OnQueryTextListener, OnItemClickListener  {

public EditText et_search;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.search_post);
.
.
.
.
et_search = (EditText)findViewById(R.id.et_search);
InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(linearLayout.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);

et_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
Log.i("Done pressed", "Enter pressed");
search.searchPost(et_search.getText().toString().trim());
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return false;
}
});


et_search.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(et_search, InputMethodManager.SHOW_FORCED);
} else {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
});

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com