androidedittext換行
① 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;
}
});
用這個偵聽方法。