1. 程式人生 > >Android tips(一)-->Android統一顯示¥符號

Android tips(一)-->Android統一顯示¥符號

新版本一個需求在使用者介面上需要顯示中文金額符號“¥”,結果這個字元在有的Android手機上顯示一個橫槓,在有的手機上顯示兩個橫槓,這是因為不同的android手機自帶的系統字型是不一致的,因此這個金額符號顯示的可能也不一致,這種需求有幾種方式:
(1)不管他(就是直接根據系統自帶的字型來顯示是一個橫槓的就顯示一個橫槓,是兩個橫槓的就顯示兩個橫槓,問題不是很大,前提是你的產品經理比較好說話。。。)
(2)使用圖片的方式(讓美工做一張金額符號的圖片,這樣就保持了顯示介面的統一)
(3)複製“¥”使用這個字元
(4)自定義元件,使用自帶的字型(統一金額符號的顯示)

public class
MoneyTextViewextendsTextView{
private static volatile Typeface moneyFont; public MoneyTextView(Context context) { this(context, null); } public MoneyTextView(Context context, AttributeSet attrs){ super(context, attrs); setCustomFont(context); } private
void setCustomFont(Context context) { if(moneyFont == null){ synchronized(MoneyTextView.class){ if(moneyFont == null){ AssetManager assertMgr = context.getAssets(); moneyFont = Typeface.createFromAsset(assertMgr, "fonts/money.otf"
); } } } setTypeface(moneyFont); } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

以上各種方式各有優劣,可以根據具體的情況選擇不同的方式。

(function () {('pre.prettyprint code').each(function () { var lines = (this).text().split(\n).length;varnumbering = $('').addClass('pre-numbering').hide(); (this).addClass(hasnumbering).parent().append(numbering); for (i = 1; i