我创建了一个带有多行编辑文本字段的对话框。问题是软键盘的 [ENTER] 键正在关闭键盘而不是创建新行。使用 imeOptions,可以配置很多,但不能配置换行命令......我怎样才能完成这个?
为搭载 Android 4.0.3 的 Galaxy Tab 2 构建。
我试图在每次用户在框中输入字符时进行检查EditText。
有某种类型的吗OnChangeListener?
好吧,如果输入几行,有很多示例如何使 editText 的高度可扩展。但我的 editText 应该在屏幕底部。我的 editText 现在不可扩展。

我的代码在这里:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:orientation="vertical"
android:layout_weight="12"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
</LinearLayout>
</ScrollView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:id="@+id/editMessage"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:inputType="textMultiLine|textCapSentences"
android:minLines="3"
android:gravity="top|left"
android:maxLines="5"
android:layout_gravity= "center_vertical|center_horizontal"
android:textColor="@color/text1"
android:layout_weight="5"
android:background="@drawable/edit"
android:scrollHorizontally="false"
/>
<Button
android:id="@+id/buttonSend"
android:text='>'
android:gravity="center"
android:layout_gravity= "center_vertical|center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@drawable/button_normal"
/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
请问有什么想法吗?谢谢!
我是 Android 新手.. 我有一个大小为 250dp 的 textview.. 我正在尝试计算其中的文本宽度.. 但我找不到任何返回实际内容宽度的 API.. 有人可以帮忙吗?完毕。提前致谢。
EditText有奇怪的行为。我在里面写的任何东西都只写在一行中。我无法在第二行(新行)中写入文本。
为什么我不能写多行文本?
这是我的 EditText
<EditText
android:id="@+id/tbr_des"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/des"
android:inputType="textCapSentences"
android:textColorHint="@color/text_hint"
android:textColor="@color/text"
android:maxLength="300"
android:layout_margin="10dp"
android:padding="5dp"
android:gravity="start"
android:background="@drawable/edit_text"/>
Run Code Online (Sandbox Code Playgroud)
而我的另一个活动具有相同EditText的所有属性,它允许我写多行。我LinearLayout在两个 xml 中都使用。
EditText 的另一种布局。
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/des"
android:textColorHint="@color/text_hint"
android:textColor="@color/text"
android:maxLength="300"
android:layout_margin="10dp"
android:padding="5dp"
android:gravity="start"
android:background="@drawable/edit_text"/>
Run Code Online (Sandbox Code Playgroud)
我也试过,android:singleLine="false"但不起作用。
我目前正在开发一个 android 应用程序,但我在使用 EditText 时遇到了一些问题。
我想创建一个带有空字符串的 editText,其高度等于 1 行或更多行并保持该高度,但当文本开始溢出到当前大小以下时允许它增长。
我尝试了几件事:
如果我将 Edittext 的大小设置为某个值,它就不会增长......前面的行只会上升并变得不可见
当我不设置大小并使用默认高度时,edittext 总是以两行的高度开始,而不是 1 行。
我怎样才能解决这个问题?
我已经创建了 EditText 也为这个背景创建了 xml,如下面的附加代码
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/login_editext_blue_border"/>
<item
android:state_focused="true"
android:drawable="@drawable/login_editext_blue_border"/>
<item
android:drawable="@drawable/login_editext_grey_border"/>
Run Code Online (Sandbox Code Playgroud)
然后我将其添加为 EditText 的背景
我用它作为我的应用主题
Theme.AppCompat.Light.DarkActionBar
Run Code Online (Sandbox Code Playgroud)
现在,如果运行我的应用程序,则 EditText 背景显示为黑色背景,如下图在 android Galaxy S3 mini 4.1.2 中

请为此提出解决方案。
我试图让用户在编辑文本中输入文本。当用户按下回车键时,我想从编辑文本中取出文本并将其添加到我的 ArrayList 中。我在从编辑文本控制 keyEvent 时遇到问题。
public class MainActivity extends Activity {
ArrayList<String> array_list;
ListAdapter lv;
ListView list;
EditText edittext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
array_list = new ArrayList<String>();
edittext = (EditText) findViewById(R.id.textView);
lv = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array_list);
list = (ListView) findViewById(R.id.lstView);
list.setAdapter(lv);
edittext.requestFocus();
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_GO) {
array_list.add(edittext.getText().toString());
edittext.setText("");
edittext.requestFocus();
}
return handled;
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
所以我需要做的是当用户按下回车键时,它从字段中获取文本并将其添加到一个数组列表中。然后它从文本字段中删除文本并再次为其提供焦点。
我正在使用EditText内部 a Toolbar,无论我做什么,都不会出现光标和下划线
xml代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
app:collapseIcon="@drawable/ic_arrow_up_24dp"
app:titleTextColor="@color/white"
android:layout_alignParentTop="true"
android:animateLayoutChanges="true"
android:visibility="gone"
android:alpha="0.0"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:cursorVisible="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="wrap_content"
android:hint="Search..."
android:textCursorDrawable="@color/white"
android:textColor="@color/md_white_1000"
android:layout_marginRight="120dp"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
科特林代码
editText?.visibility = View.VISIBLE
editText?.requestFocus()
editText?.isCursorVisible = true
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setTextIsSelectable(true);
Run Code Online (Sandbox Code Playgroud)
我哪里出错了,有人可以帮忙吗?
我尝试Firestore使用我输入的字母将搜索集成到集合中EditText。我的意思是,我怎么能在没有任何按钮的情况下做到这一点,只是实时搜索,即当我输入任何字母EditText并且结果出现在ListView.
我的班级,我从 Firestore 检索了所有记录:
public class AllPlaces extends AppCompatActivity {
private EditText eName;
private ListView mList;
private FirebaseFirestore firestore = FirebaseFirestore.getInstance();
private CollectionReference reference = firestore.collection("Users");
private SearchAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_places);
mList = findViewById(R.id.listSearch);
eName = findViewById(R.id.editSearch);
reference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
List<SearchModel> names = new ArrayList<>();
if(task.isSuccessful()){
for(QueryDocumentSnapshot document : task.getResult()) {
SearchModel model = document.toObject(SearchModel.class);
names.add(model);
}
mList = …Run Code Online (Sandbox Code Playgroud) search android android-edittext firebase google-cloud-firestore