2016-08-01 105 views
1

你好我的編輯文本面臨問題。Edittext首字母不自動大寫

的EDITTEXT的XML粘貼如下:

<EditText 
       android:id="@+id/edttxt_description_taskdescription" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="@dimen/padding_large" 
       android:layout_marginTop="@dimen/margin_.5x" 
       android:background="@color/white" 
       android:lines="2" 
       android:gravity="top" 
       android:hint="@string/activity_task_description_name_hint" 
       android:imeOptions="actionDone" 
       android:singleLine="false" 
       android:inputType="textMultiLine|textCapSentences" 
       android:maxLength="85" 
       android:textSize="@dimen/text_16pixels" /> 

問題:我要自動大寫的EditText的第一個字母,但情況並非如此。請幫忙 !

注:我想要一個多行EditText。

+0

其實這個代碼正在啓動字作爲資本你letter.Could請verify.Do你需要在一條線上的大寫字母每一個字每一個線? –

+0

嘗試在inputType中添加textCapWords,如android:inputType =「textMultiLine | textCapWords | textCapSentences」。 – mubeen

+0

我剛剛測試了你的代碼,它適用於我。你是否在你的代碼中編輯地修改EditText? – babadaba

回答

-2
android:inputType="textCapSentences" 
+0

已經試過了! –

0

你可以在你的活動中使用這段代碼做一個大寫的句子。在每個句子中,第一個字母大寫和新的句子意味着在點(。)和空格之後。

for example: 
i/p---> hi hello. hi hello  
    o/p---> Hi hello. Hi Hello 

使用此代碼

EditText assignmentName=(EditText) findViewById(R.id.assignmentNameId); 
    String sassignmentName = assignmentName.getText().toString(); 
    char[] assignment=sassignmentName.toCharArray(); 
       char[] assignment1=new char[assignment.length]; 
       int count=0; 
       for(int i=0;i<=assignment.length-1;i++) 
       { 
        if(i==0 && Character.isLowerCase(assignment[i])) { 
         char first = assignment[i]; 
         char first1 = Character.toUpperCase(first); 
         assignment1[count] = first1; 
         count++; 
        }else if(Character.isWhitespace(assignment[i-1]) && assignment[i-2]=='.' && Character.isLowerCase(assignment[i])) 
        { 
         char first = assignment[i]; 
         char first1 = Character.toUpperCase(first); 
         assignment1[count] = first1; 
         count++; 
        } 
        else { 
         assignment1[count]=assignment[i]; 
         count++; 
        } 
       } 
       String UpperCaseassignmentName=String.valueOf(assignment1); 
1

你應該已經改變了的inputType textCapSentences到textCapWords。

<EditText 
      android:id="@+id/edttxt_description_taskdescription" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="@dimen/padding_large" 
      android:layout_marginTop="@dimen/margin_.5x" 
      android:background="@color/white" 
      android:lines="2" 
      android:gravity="top" 
      android:hint="@string/activity_task_description_name_hint" 
      android:imeOptions="actionDone" 
      android:singleLine="false" 
      android:inputType="textMultiLine|textCapWords" 
      android:maxLength="85" 
      android:textSize="@dimen/text_16pixels" />