[英]Unwanted padding or margin around buttons in Android
這是我運行該應用程序時當前的樣子:
如您所見,按鈕周圍有某種邊距/填充。 我希望他們理想地從邊緣走到邊緣。 我嘗試更改邊距、填充和約束。
下面是兩個按鈕(在 LinearLayout 中)的 XML 當前的樣子。
<Button
android:id="@+id/cameraPageButton"
android:layout_width="match_parent"
android:layout_height="150dp"
android:text="@string/cameraPageButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:backgroundTint="@color/CallPageButton"/>
<Button
android:id="@+id/messagePageButton"
android:layout_width="match_parent"
android:layout_height="150dp"
android:backgroundTint="@color/MessagePageButton"
android:text="@string/messagePageButton"
app:layout_constraintBottom_toTopOf="@id/cameraPageButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
您可以簡單地用您的顏色覆蓋默認背景
<Button
android:id="@+id/cameraPageButton"
android:layout_width="match_parent"
android:layout_height="150dp"
android:text="Camera Page Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@color/colorAccent"
app:layout_constraintStart_toStartOf="parent"/>
我認為您無法在 XML 中修改此行為。 在我個人看來,你可以使用一個 TextView 來達到同樣的效果。 如果您需要類似的背景(如默認的 Button 本身),您可以創建一個帶有圓角的 drawable,如果您也需要一個輕微的陰影,您可以添加高度。
<TextView
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#fff"
android:fontFamily="@font/m_bo"
android:gravity="center"
android:text="press"
android:textAllCaps="true"
android:textColor="#242424"
android:textSize="@dimen/text_size_large" />
使用支持庫 v7,所有樣式實際上都已經定義並可以使用。
所以你可以像這樣設置你的按鈕樣式,它會填滿所有的空間
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="BUTTON"
android:gravity="center"
android:minHeight="0dp"
android:minWidth="0dp"
android:background="@color/colorAccent"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.