2012-07-03 30 views
1

我想爲ICS製作1x1小部件,它在圖標下方顯示文本標籤,並使用設備的默認文本樣式,但無法找出如何完成此操作。我知道這是可能的,因爲許多與我的Galaxy Nexus一起上市的1x1小部件都具有此功能。我不想在佈局文件中對textView進行硬編碼,因爲這會使其在其他設備上看起來很糟糕,這可能會使用不同的字體和文本大小等。Android ICS 1x1小部件文本標籤

任何人有什麼想法?

+0

您應該使用'android-widget'而不是'widget'。你的問題會得到同樣多的關注,我保證:) –

+0

@AlexLockwood但他似乎在問一個主屏幕小部件,它與android-widget標籤(Android應用程序中的UI元素,如Button,TextView,CheckBox等) – FoamyGuy

+0

嗯...我想這是真的。但它有點像Tag Wiki這樣的問題......現在ICS已經走了,你不覺得'android-widget'應該用於這個目的嗎?無論如何,'Button','TextView'等都應該在'View'下標記。另外,'widget'非常普遍,可以應用於一堆不同的事物。 –

回答

1

我不認爲你可以繞過將TextView放入佈局。你可以做的是從內置的Android風格之一爲它選擇風格。這樣它應該匹配所有其他圖標/小部件標籤。希望這可以在其他API版本中起作用,但我知道它在我的ICS手機上看起來很正確。我也不確定FrameLayout是否是在這裏使用的最好的東西,但我認爲我會做一些實驗。最重要的部分是TextView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <FrameLayout 
     android:id="@+id/FrameLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" > 
     <ImageButton 
      android:id="@+id/buttonimg" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@drawable/appwidget_dark_bg_clickable" 
      android:clickable="true" 
      android:contentDescription="@string/app_name" /> 
     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:contentDescription="@string/app_name" 
      android:src="@drawable/arrow_dark" /> 
    </FrameLayout> 
    <TextView 
     android:id="@+id/labelTextView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textAppearance="@android:style/TextAppearance.DeviceDefault.Widget" 
     android:text="@string/widgetlabeldefault" /> 
</LinearLayout> 
+0

謝謝,這對我有用.. –

相關問題