簡體   English   中英

Android:在白色背景上跟蹤switchcompat隱形

[英]Android: track invisible for switchcompat when on white background

我有一個背景為白色的活動,我添加了一個switchcompat,但是當開關未激活(關閉)時,該軌道是不可見的。 所有可見的都是拇指,因此對於用戶來說,它根本不是一個開關。 當開關處於非活動位置時,如何使開關的軌跡可見?

                    <android.support.v7.widget.SwitchCompat
                        android:id="@+id/someswitchname"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentEnd="true"
                        />

這樣做的方法是定義一個這樣的自定義主題:

<style name="Custom.SwitchCompat.WhiteTrack" parent="Base.Widget.AppCompat.CompoundButton.Switch">
        <!-- Inactive track color(30% transparency) -->
        <item name="android:colorForeground">[some color]</item>
    </style>

然后在你的布局中定義主題,如下所示:

android:theme="@style/Custom.SwitchCompat.WhiteTrack"

etvoilà。

暫無
暫無

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

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