簡體   English   中英

如何更改按鈕的主題?

[英]How to change theme for button?

在我的應用中,我使用自己的主題“ Theme.prehladna”,在其中我將“默認”主題“ Theme”用作父主題。 問題在於父主題“主題”包含所有按鈕的主題:垂直/水平居中。 我需要刪除垂直居中。 (如果我知道怎么做,那么我可以更改其他設置)。 下面也是我的名為“ Bttn.center”的按鈕的主題,其中父主題為widget.button(水平,垂直居中)。 我試圖更改Theme.prehladna(位於其下方和下方)的按鈕主題,但這種方式不起作用(顯示錯誤,找不到資源)。 您能幫我編輯代碼以完成我需要的工作嗎?

* 更新: *下面的代碼已得到糾正,但是我仍然具有水平居中以及垂直居中的按鈕。 下面的代碼以某種方式不會影響我的按鈕。 PS Theme.prehladna適用於Android清單中的活動。 我做錯了什么?

styles.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Prehladna" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>

<!-- Button styles -->
<item name="android:buttonStyle">@android:style/Bttn.center</item> <<<<<<here Eclipse says No resource found<<<<<<<
CORRECT CODE: 
<item name="android:buttonStyle">@style/Bttn.center</item> 

</style>

<style name="Bttn.center" parent="android:Widget.Button">        
<item name="android:gravity">center_horizontal</item>      
</style>

您正在使用@android:style/Bttn.center ,但是您的樣式不是Android框架中包含的默認樣式。 請改用此: @style/Bttn.center

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM