2013-03-09 70 views
0

我要讓像果凍豆一時鐘(粗體小時和分鐘正常)這樣的形象: enter image description here果凍豆數字時鐘

我下載了EditClock部件從Android的開源,時鐘的作品,但我不能使用以下代碼製作「Bold」工作即時貼: EditClock Source Code 即時貼上果凍豆字體。 這是我的佈局

<com.myApp.views.DigitalClock 
     android:id="@+id/digitalClock1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/musicDashboard" 
     android:layout_centerHorizontal="true" > 

     <TextView android:id="@+id/timeDisplayBackground" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:textColor="#ffffffff" 
      android:textSize="@dimen/clock_text_size" 

      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_marginBottom="6dip" 
      android:ellipsize="none" 
      /> 

     <TextView android:id="@+id/timeDisplayForeground" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:ellipsize="none" 
      android:textStyle="bold" 
      android:textColor="#ffffffff" 
      android:layout_alignStart="@+id/timeDisplayBackground" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:layout_alignTop="@+id/timeDisplayBackground" 
      android:layout_marginBottom="6dip" 
      android:textSize="@dimen/clock_text_size" 
      /> 
    </com.myApp.views.DigitalClock> 

我怎樣才能使這項工作的一部分?在薑餅和上? 謝謝

回答

1

您可以修改DigitalClock小部件的代碼,以在文本的第一部分添加Span。試試這個代碼在updateTime()方法:

CharSequence newTime = DateFormat.format(mFormat, mCalendar); 
SpannableString spannable = new SpannableString(newTime); 
int endIndex = spannable.indexOf(':'); 
spannable.setSpan(new StylePan(Typeface.BOLD), 0, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
mTimeDisplayBackground.setText(spannable); 
mTimeDisplayForeground.setText(spannable); 
mAmPm.setIsMorning(mCalendar.get(Calendar.AM_PM) == 0); 
+0

是的,它的工作原理,但是,大膽比分鐘sighly不同,它的任何方式,其中分鐘比小時稀釋劑? – Javier 2013-03-09 04:51:11

+0

Android沒有提供「使其變得更大膽」或「變得更薄」的機制。所有你需要處理的是類似於代碼片段中使用的字體樣式常量。如果你真的認爲它是值得的,你可以嘗試使用自定義字體。 – Karakuri 2013-03-09 05:36:28

+0

似乎我不能讓它的工作:(至少不是我想要的,也許它是一個很好的aproach「看起來」像我想要的感謝 – Javier 2013-03-09 06:58:22