2017-02-05 14 views
0

edittextを1行だけに制限する方法を教えてもらえますか?Edittext 1行を表示

スクリーンショット:

enter image description here

私のxml:

<EditText 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:hint="Full Name" 
android:id="@+id/textView_data2" 
android:textSize="20sp" 
android:layout_marginTop="10dp" 
android:layout_marginBottom="10dp" 
android:maxLines="1" 
android:gravity="fill_vertical" /> 
+2

MAXLINESはとにかく –

+0

MAXLINESをPERSONNAMEするinputTypeを設定してみてください、それを行う必要がありますが、あなたが達成しようとしている何をすべきか男だ!あなたはすでにそのように見てください持っていますあなたの重力とtextSizeで。 –

+0

@AshishRanjan Sweetこれは私が探していたものです.haha、私は自分の投稿を更新します。 – iamcoder

答えて

1
<EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:hint="Full Name" 
       android:scrollHorizontally="false" 
       android:id="@+id/textView_data2" 
       android:textSize="20sp" 
       android:layout_marginTop="10dp" 
       android:layout_marginBottom="10dp" 
       android:maxLines="1" 
       android:inputType="textPersonName" 
       android:gravity="fill_vertical" /> 
+1

トップフィードに提案されたinputTypeを追加することにより、編集テキストは、テキストが編集テキストの制限サイズに達したときは常に1行として動作します。 – iamcoder

+0

これを回答の説明に追加すると、今後同様の問題を抱える人に役立ちます。 –

+0

@AshishRanjanはい、私はすでに回答として投稿しました。 – iamcoder

0

はちょうどあなたのXML-ファイルに追加の2行があるandroid:maxLines="1"

0
<EditText 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:hint="Full Name" 
android:id="@+id/textView_data2" 
android:textSize="20sp" 
android:layout_marginTop="10dp" 
android:layout_marginBottom="10dp" 
android:inputType="text" 
android:imeOption="actionNext" 
android:gravity="fill_vertical" /> 


android:inputType="text" 
android:imeOption="actionNext" 

キャッチ。あなたはより良いimeOption でactionDon
すなわち、
android:imeOption="actionDone"

使用これを使用すると、あなたはすべての良い:)

P.S.ですアンドロイドによって提供される複数のタイプのimeOptionがあります。私たちは通常、softKeyboardInputにこれらのimeOptionsを使用し、キーパッドのEnterボタンを他のものに変更する必要があります。
例えば、
actionDone:DONEボタン
actionNext:これらのimeOptionのみinputType = "テキストと連動し、次のエディットボックスに移動し、など、

|数| ..

あなたが使用するための入力タイプを指定する必要があります。すなわちimeOption。

が、それはあなたを助けることを願っています:)

関連する問題