在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):savvyapps/ToggleButtonLayout开源软件地址(OpenSource Url):https://github.com/savvyapps/ToggleButtonLayout开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):ToggleButtonLayoutEasy creation and management of toggle buttons from the Material Design spec. Read more about ToggleButtonLayout in our blog post. DependencyAdd this in your root allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
} Then, add the library to your project dependencies {
implementation 'com.github.savvyapps:ToggleButtonLayout:latest.version.here'
} UsageAdd the ToggleButtonLayout to your layout: <com.savvyapps.togglebuttonlayout.ToggleButtonLayout
android:id="@+id/toggle_button_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp"
app:menu="@menu/toggles" /> where the toggles menu looks like: <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/toggle_left"
android:icon="@drawable/ic_format_align_left_black_24dp" />
<item
android:id="@+id/toggle_center"
android:icon="@drawable/ic_format_align_center_black_24dp" />
<item
android:id="@+id/toggle_right"
android:icon="@drawable/ic_format_align_right_black_24dp" />
</menu> You can safely ignore lint warnings about needing a title on each item, unless you want a title to appear on each item. Later, you can get the selected items via: val selectedToggles = toggleButtonLayout.selectedToggles()
//do what you need to with these selected toggles And you can listen for when toggles are switched: toggleButtonLayout.onToggledListener = { toggle, selected ->
Snackbar.make(root, "Toggle " + toggle.id + " selected state " + selected, Snackbar.LENGTH_LONG)
.show()
} CustomizationYou can customize the <com.savvyapps.togglebuttonlayout.ToggleButtonLayout
android:id="@+id/toggle_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="16dp"
app:allowDeselection="false"
app:customLayout="@layout/view_toggle_button"
app:dividerColor="@android:color/darker_gray"
app:selectedColor="?attr/colorAccent"
app:menu="@menu/toggles"
app:multipleSelection="true"
app:toggleMode="even" /> If you use the Notes
License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论