我希望iOS和Android上的按鈕文字顏色相同。所以我想我只是將代碼中的TextColor屬性設置爲我想要的顏色。在iOS上,禁用的文本顏色仍然是灰色的(這是我想要的),但是,在Android上,禁用的文本顏色與啓用的文本顏色相同。如何在Android灰色上設置禁用的文本顏色(或者默認爲禁用按鈕的顏色)? 謝謝Xamarin表單按鈕TextColor在Android上的表現與iOS相比有所不同
3
A
回答
7
這是Xamarin.Forms中的默認行爲。若要解決,實現了自定義顏色,您可以:
- 使用觸發器來改變從啓用已禁用去,反之亦然當顏色
- 手動設置顏色啓用和禁用按鈕
- 時使用自定義渲染
因爲觸發器是實現你想要什麼的最簡單,一致的方式,我只覆蓋。有關自定義渲染器的更多信息,請參閱xamarin docs。
使用觸發器時,您可以在未啓用時動態地將字體顏色更改爲灰色。有關觸發器的更多信息,請參見docs。
<Button Text="I am a Button">
<Button.Triggers>
<Trigger TargetType="Button"
Property="IsEnabled" Value="true">
<Setter Property="TextColor" Value="Red" />
<!-- red is the desired color when the button is enabled.-->
</Trigger>
<Trigger TargetType="Button"
Property="IsEnabled" Value="false">
<Setter Property="TextColor" Value="Gray" />
<!-- gray is the desired color when the button is disabled.-->
</Trigger>
</Button.Triggers>
</Button>
0
如果上述方法不爲你工作,你可以嘗試檢查this workaround。它使用自定義渲染器和NSAttributedString
設置標題在禁用狀態
相關問題
- 1. swift的繪圖代碼在tvOS上的表現與iOS相比有所不同
- 2. 按鈕在所有的比賽中不呈現相同
- 3. Xamarin表單按鈕綁定
- 4. Unity ScreenToWorldPoint在Mac上表現不同(與PC相比)?
- 5. 顯示用戶在Xamarin表單上按下按鈕時的按鈕列表
- 6. 單選按鈕列表selectedItem.Value與字符串相比不工作
- 7. 升級後的xamarin表單不能正確呈現按鈕
- 8. 相同的聯繫表單在不同的託管賬戶上表現不同
- 9. UITableViewCell在iOS 8上的高度不同(與iOS 7相比)
- 10. Codename one:爲什麼android按鈕有不同的外觀比IOS按鈕
- 11. Listview項不會在android上呈現xamarin表單
- 12. 所有Android設備上UI元素(按鈕,圖像按鈕)的位置相同
- 13. 同時具有相同表單的多個按鈕
- 14. 具有與單選按鈕相同行爲的HTML按鈕組
- 15. 按鈕textcolor沒有改變
- 16. Android - 按鈕的textColor與選擇器不工作
- 17. Android上的單選按鈕列表
- 18. 如何提交表單與相同值的多按鈕ASP.NETMVC
- 19. Xamarin表單 - 強制回顯按鈕
- 20. Xamarin表單Facebook登錄按鈕
- 21. Xamarin表單圖片按鈕問題
- 22. 如何在不同的單選按鈕上打開不同的表單
- 23. 觸發相同Id的所有按鈕
- 24. 使所有按鈕的大小相同
- 25. 如何在xamarin表單上做複合按鈕?
- 26. 使「向上」按鈕的行爲與Android上的「返回」按鈕相同
- 27. Xamarin表單BarBackground在Android上丟失了
- 28. Xamarin表單按鈕中的Android資源名稱
- 29. Xamarin表單中的Android Activity或iOS ViewController表單ContentPage
- 30. 如何爲相同的表單傳遞相同的模型有兩個按鈕
使用自定義渲染器:https://stackoverflow.com/a/49193488/1039935 – Arvis