当前位置:首页 » 安卓系统 » androidedittext换行

androidedittext换行

发布时间: 2022-11-21 12:46:10

① android中我将 EditText 的singleline属性设置false依然不自动换行

singleline属性不是
自动换行
,而是单行,true的情况下只能输入一行,false可以多行,不过新的sdk已经淘汰了这个属性

② android 怎么获取edittext输入内容中包含的换行符和回车符的个数

换行符和回车符都有相应的ascii值,声明2个char,然后从取得的edittext内容中搜索

③ Android EditText当输入文字换行后,如何让EditText的高度也随之适应整个文字的高度呢

我也遇到同样问题,以下是我解决问题方法,仅供参考。
默认EditText设置warp-content就可以,但是我一直不可以,最终发现是布局有问题,因为在editText中设置了gravity="center_vertical",所以一直被截一半,导致显示不全,后来我改成了layout_gravity="center_vertical" 就可以了,这是我全部的代码,我设置了最多字数,你可以不限制
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:background="@color/white">

<TextView
style="@style/style_left_title_light_color"
android:layout_width="80dp"
android:layout_height="45dp"
android:text="备注" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:background="@color/white"
android:textSize="16dp"
android:textColor="@color/colorPayBtn"
android:textColorHint="@color/colorLightGray"
android:hint="请填写备注"
android:maxLength="50" />
</LinearLayout>
style:
<style name="style_left_title_light_color">
<item name="android:layout_height">match_parent</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textSize">16dp</item>
<item name="android:textColor">@color/gray</item>

</style>

④ 安卓edittext换行,androidEditText问题怎么才能在文本框里

读取edittext的内容用gettext().tostring().trim();就可以,trim()是去掉前后空格的,可以差资料看看
截取字符串的话,看这个字符串是固定的位数吗?还是什么?
可以用indexof获取某个字符第一此出现的索引,然后用substring()截取字符串

安卓软件开发中怎么让一个EditText自动换行

packagecom.example.android.helloactivity;

importandroid.content.Context;

importandroid.graphics.Paint;

importandroid.graphics.Rect;

importandroid.text.TextPaint;

importandroid.util.AttributeSet;

importandroid.view.Display;

importandroid.view.KeyEvent;

importandroid.view.WindowManager;

importandroid.widget.EditText;

{

intscreenWidth=0;

intscreenHeight=0;

intcurrentHeight=0;

Contextcontext=null;

publicMyEditor(Contextcontext,AttributeSetattrs){

super(context,attrs);

this.context=context;

currentHeight=getHeight();

WindowManagerwindowManager=(WindowManager)this.context

.getSystemService(Context.WINDOW_SERVICE);

Displaydisplay=windowManager.getDefaultDisplay();

//取得屏幕宽度和高度

screenWidth=display.getWidth();

screenHeight=display.getHeight();

setScrollBarStyle(DRAWING_CACHE_QUALITY_AUTO);

/*Rectrect=newRect();

Paintp=newPaint();

p.setTypeface(getTypeface());

p.getTextBounds("A",0,1,rect);

fontWidth=rect.width();*/

}

@Override

publicbooleanonKeyUp(intkeyCode,KeyEventevent){

TextPaintpaint=getPaint();

floatlen=paint.measureText(getText().toString());

//计算得到当前应该有几行

intline=((int)len/screenWidth+1);

getEllipsize();

setFrame(0,0,screenWidth,line*60);

//setHeight(line*60);

//setMarqueeRepeatLimit(line);

//setMaxHeight(line*60);

//setLines(line);

//setBackgroundColor(Color.WHITE);

returnfalse;

}

}

⑥ 怎么让 android EditText hint 不换行

下面是android学习手册关于 edittext的介绍,360手机助手中可下载,例子、文档、代码随便看。


第一种,就是监听EditText的setOnEditorActionListener方法,然后把enter键禁止,这种方法有个不好的地方就是,在虚拟键盘中依然会显示enter键:

/**

*设置相关监听器

*/

privatevoidsetListener(){

userNameEdit.setOnEditorActionListener(newOnEditorActionListener(){

@Override

publicbooleanonEditorAction(TextViewv,intactionId,KeyEventevent){

return(event.getKeyCode()==KeyEvent.KEYCODE_ENTER);

}

});

}

第二种方法是直接在EditText的xml文件中通过配置android:singleLine="true"把虚拟键盘上的enter键禁止掉,不会显示。

<EditText

android:layout_width="fill_parent"

android:layout_height="38dp"

android:id="@+id/loginUserNameEdit"

android:background="@android:color/white"

android:hint="登录账户"

android:paddingLeft="10dp"

android:maxLines="1"

android:singleLine="true"

/>

感觉第二种方法更好一些

⑦ android Edittext 输入文字时 怎么限制限制回车换行急 谢了

在layout的xml中添加这样的属性 android:singleLine="true" 就不会换行了。

⑧ android textview 怎么换行

textView如果想要强制换行的话,必须先把TextView显示方式修改为多行(android:singleLine="false"),然后才能换行。
方法一般用两种:

1、在字符串里加入“ ”,如"abc rc";

2、把TextView设置为固定宽度,然后让系统自动换行。如android:layout_width="100dp";

(8)androidedittext换行扩展阅读

Class Overview

向用户显示文本,并可选择允许他们编辑文本。TextView是一个完整的文本编辑器,但是基类为不允许编辑;其子类EditText允许文本编辑。

允许用户复制部分或全部内容,将其粘贴到别的地方,设置XML属性Android:textisselectable :“真” 或设置相关方法 settextisselectable 为“真”。textisselectable flag 允许用户在TextView选择手势,从而触发系统内置的复制/粘贴控件。

Displays text to the user and optionally allows them to edit it. A TextView is a complete text editor, however the basic class is configured to not allow editing; seeEditTextfor a subclass that configures the text view for editing.

To allow users to some or all of the TextView's value and paste it somewhere else, set the XML attributeandroid:textIsSelectableto "true" or callsetTextIsSelectable(true). ThetextIsSelectableflag allows users to make selection gestures in the TextView, which in turn triggers the system's built-in /paste controls.

⑨ Android 实现 EditText 文本自动换行

很简单,在布局 XML 文件的 EditText 中加上下面这行:
android:inputType="textMultiLine"

即可。

⑩ android开发,edittext监听跳转的时候会先换行,然后光标再跳入下一个edittext,这是怎么回事

enter按键按下才触发键盘侦听事件,所以会有enter效果。
et.setOnEditorActionListener(new TextView.OnEditorActionListener() {

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub

if(actionId==EditorInfo.IME_ACTION_UNSPECIFIED){
name.requestFocus();
}
return true;
}
});
用这个侦听方法。

热点内容
php匹配标点符号 发布:2024-05-19 21:14:49 浏览:752
可以拍照输入的c语言编译器 发布:2024-05-19 21:09:47 浏览:181
解压升降机 发布:2024-05-19 20:51:11 浏览:967
请稍作停留密码是什么意思 发布:2024-05-19 20:37:12 浏览:244
linux结束符 发布:2024-05-19 20:33:05 浏览:817
招标服务器云 发布:2024-05-19 20:04:19 浏览:584
搭建小米云服务器 发布:2024-05-19 19:43:17 浏览:131
苹果手机备忘录怎么加密 发布:2024-05-19 18:57:57 浏览:16
光荣脚本 发布:2024-05-19 18:57:48 浏览:997
pythonjson字符串 发布:2024-05-19 18:51:43 浏览:253