2013-07-07 46 views
1

我有一個提示文本框,但我希望始終顯示提示,即使在TB中有輸入。示例是Gmail應用中的「收件人」字段。編輯框提示 - 始終顯示提示

+1

我不認爲它在那裏是一個提示,你可以看到光標只在'到'之後開始。但是,你可以通過使用LinearLayout來模仿它,如果你同意這種方法,我會編寫一個完整的答案。 –

+0

聽起來對我很好,你介意嗎? –

+1

沒問題 - 增加了一個答案,我建議你使用選項3,讓我知道如果你有任何問題。 –

回答

2

有,你可以使用3種方法(擾流板 - 用3號),因爲在我的評論在Gmail的例子提到,它不是一個實際的提示:

  1. 使用線性佈局,漸漸在我看來,一個整潔的外觀:

    <LinearLayout android:layout_width="fill_parent" 
          android:layout_height="wrap_content"> 
    <TextView android:text="@string/Hint" 
          android:layout_margin="5dp" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"/> 
    <EditText android:layout_width="fill_parent" 
          android:inputType="text" 
          android:layout_height="wrap_content"/>  
    </LinearLayout> 
    
  2. 使用相對佈局,讓模仿的Gmail應用程序的結果:

    注:可能是問題,因爲文本將在提示的頂部顯示,請參閱解決方案3.

    <RelativeLayout android:layout_marginTop="10dp" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content"> 
        <TextView android:text="@string/Hint" 
          android:paddingLeft="10dp" 
          android:layout_marginBottom="0dp" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content"/> 
        <EditText android:layout_width="fill_parent" 
          android:inputType="text" 
          android:layout_height="wrap_content"/>  
    

    結果都如本圖所示:

    Custom Permanent Hint

    編輯:

  3. 使用可繪製

    這似乎是一個更好的解決方案(我個人剛剛從剪斷1中創建它:TextView的1顯示,將在正確的測量這種方式),這將允許一個清晰的佈局代碼和文本將意識到繪製的:

    <RelativeLayout android:layout_marginTop="10dp" 
        android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          > 
    <EditText android:layout_width="fill_parent" 
          android:inputType="text" 
          android:gravity="top" 
          android:drawableLeft="@drawable/Hint" 
          android:layout_height="wrap_content"/>  
    

    Drawable Hint

0

首先想到的是插入兩個editText佈局相對佈局。 首先在second.at頂部 - 把背景作爲 android.R.color.transparent 工作與相對佈局的頂部elevent!在下面的項目 - 設置提示(你想要的),並嘗試把文字。也許你會指定頂部第一個元素的填充來顯示。

哦。還有一件事。 也許把editText背景背景圖片 - 但是可擴展性不好。