2013-04-21 39 views
1

我想用多種顏色主題爲我的Android應用程序加皮膚。 這個指南/工具幫我生成的基本theme.xmlstyle.xml如何使用theme.xml和style.xml設置PopupMenu和AlertDialog的樣式

,但我不能算出它的風格的的PopupMenuAlertDialog標題?

我只想改變顏色來簡化我的應用主題!

例子:
before, taken from: developer.android.com/images/ui/dialogs.png

和看起來像
after, taken from: developer.android.com/images/ui/dialog_custom.png

我使用Theme.Holo Android SDK中21.1 RC3 /工具16.0。我已經嘗試了很多與風格和主題,但沒有什麼工作

回答

0
public class AlertDialogThemed extends AlertDialog { 
public AlertDialogThemed(Context context) { 
    super(context); 
} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    final Resources resources = getContext().getResources(); 
    final int color = resources.getColor(R.color.dialog_color); 

    final View title = findViewById(resources.getIdentifier("alertTitle", "id", "android")); 
    if (title != null) { 
     ((TextView) title).setTextColor(color); 
    } 

    final View titleDivider = findViewById(resources.getIdentifier("titleDivider", "id", "android")); 
    if (titleDivider != null) { 
     titleDivider.setBackgroundColor(color); 
    } 
} 

}

相關問題