切换按钮 - 怎么样?

时间:2017-11-22 10:05:05

标签: android android-layout

我在一个Android项目中工作,我想询问是否可以使用开关按钮,当它处于幻灯片模式时,按钮的其他部分会出现另一个暂停按钮?!

1 个答案:

答案 0 :(得分:1)

我希望你看起来像这样。 enter image description here

enter image description here

enter image description here

为实现此目的,您需要创建自定义drawable。

你的switch_button_custom.xml就像。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

       <Switch
        android:id="@+id/switchCustom"
        android:layout_width="96dp"
        android:layout_height="48dp"
        android:layout_gravity="center"
        android:background="@drawable/switch_button_custom"
        android:thumb="@android:color/transparent" />

</LinearLayout>

你的play_active.png

enter image description here

你的pause_active.png

enter image description here

您的活动XML就像。

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        switchCustom = findViewById(R.id.switchCustom);

        switchCustom.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if (isChecked) {
                    Toast.makeText(HomeActivity.this,
                            "Play", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(HomeActivity.this,
                            "Pause", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

最后,您的活动将会像。

struct IsFree
{
};

template <typename _Type, typename _State>
struct Input
{
};

template <typename... _Inputs>
struct Inputs
{
};

template <template <typename _Type, typename _State> class, typename... _Inputs>
struct Inputs<Input<_Type, _State>, _Inputs...> : public Inputs<_Inputs...>
{
};

我希望这是你想要实现的目标。

相关问题