android - 为 Facebook 按钮添加圆角

标签 android xml android-layout facebook-sdk-4.0

我正在尝试自定义 Android 中 facebook sdk 附带的按钮。我希望它有圆角而不是普通角,为了实现这一点,我尝试了 here 的答案。我所做的基本上是在 styles.xml 中为我的 facebook 按钮添加一个样式:

   <style name="FacebookLoginButton">
    <item name="android:background">@drawable/fbshapebtn</item>
    <item name="android:textSize">18sp</item>
    <item name="android:gravity">center</item>
</style>

作为背景,我从我的可绘制对象中引用了一个 xml,我在其中定义了我的角:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp">
    <corners
        android:bottomRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"/>
</shape>

这是我的主要布局,其中包含我引用我的样式 xml 的按钮。

  <com.facebook.login.widget.LoginButton
        android:id="@+id/login_button"
        style="@style/FacebookLoginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView"
        android:layout_alignLeft="@+id/button2"
        android:layout_alignStart="@+id/button2"
        android:layout_marginBottom="11dp"
        android:layout_alignRight="@+id/button2"
        android:layout_alignEnd="@+id/button2" />

按钮看起来没有角,但是很奇怪,因为我定义的textSize似乎被应用了,所以我不知 Prop 体是什么问题。

最佳答案

对于不想创建另一个自定义按钮的人,我使用 CardView 作为按钮的父级并处理按钮的填充以获得所需的外观:

 <android.support.v7.widget.CardView
        android:layout_width="240dp"
        android:layout_height="55dp"
        android:layout_gravity="center"
        app:cardCornerRadius="18dp">

        <com.facebook.login.widget.LoginButton
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingBottom="25dp"
            android:paddingLeft="30dp"
            android:layout_gravity="center"
            android:paddingTop="25dp" />

    </android.support.v7.widget.CardView>

enter image description here

关于android - 为 Facebook 按钮添加圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44019890/

相关文章:

android - 如何在相对布局内的图像上放置背景?

java - 使用昼夜主题时如何更改布局的背景/文本颜色

android - FLUTTER:多屏应用程序的本地化

android - 如何获取选中的单选按钮的父单选组?

c# - 系统.Xml.XPath.XPathException : Expression must evaluate to a node-set when executing SelectSingleNode ("//(artist|author)")

xml - 通过 VBA 和剪贴板将 HTML 复制到 Word 会丢失特殊字符

android - 我如何在 Android 中显示此图像?

java - 在 android studio 中使用 LatLng 的问题

java - 将图像从java服务器发送到android

PHP simplexml : why does xpath stop working?