Android默认Switch
有文字,然后Switch
开/关。我正在打开/关闭Switch
,然后是文本。不要使用其他小部件,如TextView
。我如何设置Switch
右侧文字。如何在Android中将切换文本切换到右侧?
6
A
回答
-2
我能够实现我想用的组合看:
宽度(120dp)
填充(75dp)
和switchpadding(-90dp)
8
把它包在一个没有文本值另一个布局,并添加一个TextView。看到我的代码:
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_height="wrap_content">
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/reminder" />
<TextView
android:layout_width="wrap_content"
android:text="Meeting Reminders"
android:layout_height="wrap_content" />
</LinearLayout>
+1
很好用,但是如何在'Meeting Reminders'上点击来切换'Switch'控件时如何实现,没有活动中的代码逻辑?例如'for =“@ id/reminder”' – mihkov
2
添加XML的文件,此代码:
<Switch
android:id="@+id/simpleSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:checked="false"
android:textColor="@color/black"
android:textOff="@string/no"
android:textOn="@string/yes"
android:theme="@style/SCBSwitch" />
<TextView
android:id="@+id/switchBtn_txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@+id/simpleSwitch"
android:gravity="center_horizontal" />
在活动或片段:
Switch simpleSwitchBtn = (Switch) findViewById(R.id.simpleSwitch);
final TextView switchBtn_txtView = (TextView) findViewById(R.id.switchBtn_txtView);
simpleSwitchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
switchBtn_txtView.setText("Yes");
}
else {
switchBtn_txtView.setText("No");
}
}
});
我认为它有帮助到你.... 谢谢
相关问题
- 1. 搜索从右侧切换
- 2. Android在右侧切换开关的文本
- 3. 如何对右侧导航栏切换
- 4. 抽屉在右侧抽屉中切换
- 5. 如何将切换添加到切换?
- 6. 如何将文字替换到右侧?
- 7. 如何在Firefox中切换侧边栏
- 8. 在右侧切掉的文本字段
- 9. 将标签添加到切换按钮的右侧
- 10. Android切换文本按钮?
- 11. Android的 - 文本切换
- 12. 如何在Selenium中切换和切换
- 13. 切换文本
- 14. Hide&Reveal侧切换
- 15. 在JavaScript中切换文本
- 16. jQuery切换div和切换文本
- 17. 左侧切换菜单,如在Facebook中
- 18. 切换按钮不切换在Android
- 19. Android导航抽屉切换图标右侧
- 20. 在屏幕右侧切断Android TextView
- 21. 如何在javascript和css中切换到“隐藏”时切换
- 22. Android,使文本切换器中央?
- 23. 如何区分在Android中切换活动Vs切换到主屏幕
- 24. 无法从右侧切换到左Jquery的
- 25. 如何制作将标签向右切换的苹果脚本
- 26. 如何将Bootstrap的下拉菜单放置在浮动右侧切换元素的右侧?
- 27. android双抽屉:右抽屉切换
- 28. Android:如何切换音乐?
- 29. 侧边栏切换jquery
- 30. 与onclick切换复选框切换双切换(如何阻止内部切换)
在xml中使用像android:textOn和android:textOff这样的xml属性。 –
@JiteshDalsaniya默认开关有开关文本左侧和开关有右侧。我期待切换左侧并切换文本右侧。你现在可以清理吗?期望 –