2012-08-31 33 views
1

這是我的代碼。我從來沒有看到我的應用程序有任何變化。我在resources/drawable中創建了這個。我應該如何在一個樣式應用動態主題爲所有組件通過改變文本colorfontsshapes如何改變textview,button的角落形狀,通過動態應用主題來編輯文本?

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="oval" android:padding="20dp"> 
    <solid android:color="#FFA500"/> 
    <corners android:bottomRightRadius="50dp" android:bottomLeftRadius="50dp" 
    android:topLeftRadius="50dp" android:topRightRadius="50dp"/> 
    <stroke android:color="#FFA500" android:dashWidth="50dp" /> 
</shape> 

回答

0

上面的代碼工作得很好。也許問題出在你聲明背景的方式上:你是在XML文件中還是在Java代碼中動態執行它?

+0

不是動態的,因爲我注意到主題/樣式不支持動態。所以我在Xml工作。 –

+0

好..只是看到你的代碼...只是嘗試動態地聲明背景.. Button button =(Button)findviewbyid(r.id.yourid); button.setBackgroundResource(R.drawable.yourxmlfile); ...我認爲代碼適合你 –

+0

是的,我注意到了。它已被改變,尤其是按鈕形狀。但我不應該在Java(Activity)中調用它。我需要在一個Xml文件中做到這一點。當我調用主題時,它必須完全應用於我的應用程序中的所有按鈕。 –

1

爲您的按鈕代碼創建繪製

<?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    android:shape="rectangle"> 
<gradient 
    android:startColor="#99CCFF" 
    android:endColor="#99CCFF" 
    android:angle="45"/> 
<padding android:left="6dp" 
    android:top="6dp" 
    android:right="6dp" 
    android:bottom="6dp" /> 
<corners android:radius="30dp" /> 
</shape> 

現在的shape.xml添加機器人:背景如下所示。

<Button 
    android:id="@+id/bt" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/shape"/> // shape is name of xml file created 
+0

<?xml version =「1.0」encoding =「utf-8」?> <填充機器人:左= 「6DP」 機器人:頂= 「6DP」 機器人:右= 「6DP」 機器人:底部= 「6DP」/> <梯度 android:bottomRightRadius =「50dp」android:startColor =「#FFA500」 android:endColor =「#FFA500」 android:angle =「45」/> < android:bottomLeftRadius =「50dp」 android:topLeftRadius =「50dp」android:topRightRadius =「50dp」/ > <行程 機器人:顏色= 「#FFA500」 機器人:dashWidth = 「50dp」/> //創建在res形狀/抽拉 –

+0

<按鈕 風格= 「@風格/ CustomTheme」 機器人:ID =「@ + ID/Button1" 的 的android:layout_width = 「WRAP_CONTENT」 機器人:layout_height = 「WRAP_CONTENT」 機器人:文字顏色= 「#808000」 機器人:背景= 「@繪製/ rounded_edittext」 機器人:文本= 「按鈕」/ > //在Main.xml中創建 –

相關問題