【发布时间】:2017-06-08 05:12:58
【问题描述】:
我有一个按钮,我为其设置了特定的高度,并让按钮文本填满整个按钮。我之前通过将textSize 设置为特定尺寸以填充按钮来实现这一点。
但问题是每当用户更改他/她的设备的系统字体时,它都会影响按钮文本并且文本溢出并在按钮中被剪切。如何使按钮文字大小与按钮高度匹配?
编辑
按钮的高度设置为match_parent,因为它是父小部件
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_marginEnd="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="16dp">
<Button
android:id="@+id/text_toolbar"
style="?android:attr/borderlessButtonStyle"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="36sp"
android:textColor="@color/white"
android:text="@string/k_i_n_e_c_t"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
【问题讨论】:
-
设置您的按钮高度以包裹内容,然后它会自动调整以更改文本大小。
-
查看我所做的编辑