[英]How to style google SwitchMaterial button on Android?
[英]How to reduce material.switchmaterial.SwitchMaterial end margin in android?
我在有一些空間的左邊距中使用了“com.google.android.material.switchmaterial.SwitchMaterial” 。 如何減少呢?
我需要直接對齊每個人的文本。 我沒有添加開關的結束邊距或填充,我只設置了父布局邊距。 在我的 XML 代碼和 styles 下方。請提供您的建議以減少該保證金,謝謝。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<RelativeLayout
android:id="@+id/who_can"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<com.google.android.material.textview.MaterialTextView
style="@style/TextBlackRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/video_view_result"
android:singleLine="true"
android:text="@string/who_can_view"
android:textSize="@dimen/text_small"
android:visibility="visible" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/video_view_result"
style="@style/TextBlackRegular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:singleLine="true"
android:text="Everyone"
android:textSize="@dimen/text_small" />
</RelativeLayout>
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/save_switch"
style="@style/SwitchButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/who_can"
android:checked="true"
android:text="@string/save_gallery"
android:textSize="@dimen/text_small"
app:trackTint="@color/colorSecondaryText" />
</RelativeLayout>
<style name="SwitchButtonStyle" parent="Widget.MaterialComponents.CompoundButton.Switch">
<item name="thumbTint">@drawable/switch_selector</item>
<item name="android:fontFamily">@font/font_regular</item>
<item name="android:textColor">@color/colorBlack</item>
</style>
在您的relativeLayout/topRelativeLayout
中,您添加了邊距。 這意味着您想從各個方面獲利。 這就是為什么它正在發生
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
刪除android:layout_margin="10dp"
。 添加margin_top
, margin_right
你想要做什么。
您應該為開關寬度提供換行內容,或者將其設置在新的相對布局中
如果您的結束邊距在刪除后顯示
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
然后
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/save_switch"
style="@style/SwitchButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/who_can"
android:checked="true"
android:text="@string/save_gallery"
android:textSize="@dimen/text_small"
app:trackTint="@color/colorSecondaryText" />
更改 SwitchButtonStyle 它會為您提供一些默認值,如果您共享整個文件,我們會很高興
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.