Android之hint提示字型大小修改,顯示完全

來源:互聯網
上載者:User

標籤:

                                        Android之hint提示字型大小修改,顯示完全

    1.工作中遇到一個問題,就是自訂EditText的hint提示在超大字型下會顯示不全,

    2.然後在網上搜尋了一下,在這裡記錄一下,分享給大家,在此感謝寫這的大神

    3.傳入的hint是SpannedString或者Spanned類型,就可以保持文本的自訂屬性了

import android.text.SpannableString;
import android.text.Spanned;
import android.text.SpannedString;
import android.text.style.AbsoluteSizeSpan;
import android.app.Activity;
import android.widget.EditText;
import android.widget.TextView;

EditText editText = (EditText) rootView.findViewById(R.id.et);// 建立一個可以添加屬性的文字物件SpannableString ss = new SpannableString("testString");// 建立一個屬性對象,設定文字的大小AbsoluteSizeSpan ass = new AbsoluteSizeSpan(8,true);// 附加屬性到文本ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);// 設定hinteditText.setHint(new SpannedString(ss)); // 一定要進行轉換,否則屬性會消失






但是我想說的是我找到了自訂控制項的布局檔案
<com.android.xx.xx.RecipientsEditor

android:id="@+id/recipients_editor"
android:hint="@string/to_hint_ipmsg"

android:layout_width="match_parent"
android:layout_height="match_parent"

android:gravity="center_vertical"
android:inputType="textFilter"

android:textColorHint="@color/conv_item_date_subjectr_text"
android:paddingStart="16dip"

android:layout_weight="1"
android:textColor="#000000"

/>

然後將android:layout_height="match_parent"改成android:layout_height="wrap_content"
也實現了在超大字型下hint提示顯示完整的效果,而且還可以跟著隨意切換字型大小而改變
hint提示的大小,所以我覺得這個簡單些,比上一個把hint提示字型大小寫固定要好的多。

Android之hint提示字型大小修改,顯示完全

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.