标签: switchcompat

如何在android中的开关上显示进程状态?

在材料设计指南中有一个名为“显示处理状态”的部分,我们在其中看到了一个开关的视频,拇指上有一个进度指示器。

https://material.io/design/components/selection-controls.html#switches

因为开关显示某物的实际状态,所以有时它的状态变化会有延迟。在这种情况下,可以使用处理状态动画。

处理状态是开关拇指上的动画。例如,当控制硬件功能的开关在确认其最终状态之前遇到延迟时,可以使用它。

我怎样才能达到这样的效果?那是普通 CompatSwitch 的一部分吗?有图书馆可以做到这一点吗?

android switchcompat

4
推荐指数
1
解决办法
690
查看次数

Android SwitchCompat在处于关闭状态时无法呈现跟踪

我的问题可能最好用视觉方式询问 - 我想要一个SwitchCompat开关来看看他们在Android设置应用中的表现:

这是关闭:

在此输入图像描述

这是:

在此输入图像描述

但出于某种原因,我的SwitchCompat开关在关闭时看起来像这样:

在此输入图像描述

没有灰色的"轨道"延伸到右侧.但是,当打开时,它看起来像预期的那样:

在此输入图像描述

如您所见,我已将自定义色调应用于我的应用程序.我的自定义色调应用如下:

<activity
    android:name=".editor.MySettingsEditor"
    android:theme="@style/Theme.MyCustomTheme" />
Run Code Online (Sandbox Code Playgroud)

然后,在styles.xml中:

<style name="Theme.MyCustomTheme" parent="Theme.AppCompat">    
    <item name="colorAccent">@color/myColorAccent</item>
    <item name="colorPrimary">@color/myColorPrimary</item>
    <item name="colorPrimaryDark">@color/myColorPrimaryDark</item>
    <item name="alertDialogTheme">@style/AppCompatAlertDialogStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

为了确保它不是我的自定义样式导致此问题,我通过这样做删除它:

<activity
    android:name=".editor.MySettingsEditor"
    android:theme="@style/Theme.AppCompat" />
Run Code Online (Sandbox Code Playgroud)

但仍然,"关闭"轨道不会显示,但色调颜色现在转到Android默认蓝绿色.

在此输入图像描述 在此输入图像描述

SwitchCompat当处于关闭状态时,为什么我的开关会丢失灰色轨道?

描述SwitchCompat的XML非常简单:

    <android.support.v7.widget.SwitchCompat
        android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>
Run Code Online (Sandbox Code Playgroud)

谢谢!

android switchcompat

3
推荐指数
1
解决办法
1551
查看次数

android上的SwitchCompat渲染问题

我在我的布局之一中使用 android.support.v7.widget.SwitchCompat。我的编译 sdk 版本是 25,buildTools 版本是 25.0.1,我使用的是 25.2.0 版本的 com.android.support:design 我已经重新启动了 android studio,使缓存失效,做了清理/构建。但是,我仍然无法从我的设计视图中摆脱这个错误。知道我错过了什么吗?

这是我的风格:

    <style name="AppTheme" parent="android:Theme.Holo.Light">
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
    <item name="android:editTextStyle">@style/RobotoEditTextStyle</item>
</style>

<style name="SplashTheme" parent="android:Theme.Holo.Light">
    <item name="android:windowBackground">@drawable/splash</item>
</style>

<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
    <item name="android:fontFamily">sans-serif</item>
    <item name="android:textSize">@dimen/body</item>
    <item name="android:textColor">@color/colorBlack</item>
</style>

<style name="RobotoEditTextStyle" parent="android:Widget.EditText">
    <item name="android:fontFamily">sans-serif</item>
    <item name="android:textSize">@dimen/body</item>
    <item name="android:padding">@dimen/edittext_padding</item>
</style>


<style name="CustomTabLayout" parent="CustomTabLayout">
    <item name="tabIndicatorColor">@color/colorGold</item>
    <item name="tabSelectedTextColor">@color/colorGold</item>
</style>

<style name="StyledScrollerTextAppearance">
    <item name="android:textColor">@color/colorWhite</item>
</style>

<style name="CustomSwitch">@style/CustomSwitch</style>
Run Code Online (Sandbox Code Playgroud)

以下是错误。

java.lang.NullPointerException
at android.text.StaticLayout.<init>(StaticLayout.java:422)
at android.support.v7.widget.SwitchCompat.makeLayout(SwitchCompat.java:864)
at android.support.v7.widget.SwitchCompat.onMeasure_Original(SwitchCompat.java:783)
at android.support.v7.widget.SwitchCompat.onMeasure(SwitchCompat.java)
at android.view.View.measure(View.java:19731)
at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:927)
at …
Run Code Online (Sandbox Code Playgroud)

android switchcompat

2
推荐指数
1
解决办法
859
查看次数

Android,以编程方式更改应用程序:SwitchCompat 的主题值

我想将SwitchCompat的app:theme属性值更改为其他值(@style/switchColorStyleBlue)。我怎样才能以编程方式做到这一点?(app:theme 基本上改变了切换的颜色)

<android.support.v7.widget.SwitchCompat
android:id="@+id/switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:theme="@style/switchColorStylePink"/>
Run Code Online (Sandbox Code Playgroud)

我试过这段代码,但它没有显示适当的结果:

    SwitchCompat switchCompat = new SwitchCompat(this);
    switchCompat.setId(i);
    switchCompat.setSwitchTextAppearance(getApplicationContext(), R.style.switchColorStylePink);
    switchCompat.setChecked(false);
    containerRelativeLayout.addView(switchCompat);
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我想要的是将主题(开关的颜色)从粉红色更改为蓝色,反之亦然。

user-interface android switchcompat

1
推荐指数
1
解决办法
2329
查看次数

RecyclerViewAdapter 上的 SwitchCompat

SwitchCompat在我的RecyclerView适配器中只使用一个。我需要点击项目的位置,RecyclerView当我使用TextView而不是SwitchCompat. 但是SwitchCompat没有响应,也没有返回位置。

有人可以帮我吗?这是适配器文件。

public class Setting_Recycler_Adapter extends RecyclerView.Adapter<Setting_Recycler_Adapter.ViewHolder> {

    private static final String TAG = "val" ;
    private Context mContext;
    private ArrayList<Channel_Model> channelsData;
    private Setting_Recycler_Adapter.ClickInterface click;

    public Setting_Recycler_Adapter(Context mContext, ArrayList<Channel_Model> data,Setting_Recycler_Adapter.ClickInterface clik) {
        this.mContext = mContext;
        this.channelsData = data;
        this.click = clik;
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        SwitchCompat mSwitchCompat;

        public ViewHolder(View itemView) {
            super(itemView);

            mSwitchCompat = (SwitchCompat) itemView.findViewById(R.id.setting_channel_switch);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View …
Run Code Online (Sandbox Code Playgroud)

java android switchcompat

0
推荐指数
1
解决办法
882
查看次数

如何在Android中自定义开关

在此处输入图片说明

我需要在我的应用中实现这种类型的开关

xml android switchcompat

0
推荐指数
1
解决办法
1643
查看次数

标签 统计

android ×6

switchcompat ×6

java ×1

user-interface ×1

xml ×1