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默認開關有開關文本左側和開關有右側。我期待切換左側並切換文本右側。你現在可以清理嗎?期望 –