【问题标题】:How to create button with background white and no border, only a bottom line under the text如何创建背景为白色且无边框的按钮,文本下方只有一条底线
【发布时间】:2017-04-10 06:14:01
【问题描述】:

我一直在寻找解决方案,但找不到。

我想要一个没有边框但带有底线文本的按钮(它看起来像 Web 中的链接按钮)。

下面是按钮,我尝试了以下属性:

android:style="@style/Widget.AppCompat.Button.Borderless"
android:style="?android:attr/buttonBarButtonStyle
android:style="?android:attr/borderlessButtonStyle" 
android:style="@android:style/Widget.Holo.Button.Borderless"



<Button            
android:id="@+id/ForgetPwd"            
android:layout_width="fill_parent"            
android:layout_height="wrap_content"            
android:layout_margin="10dp"            
android:background="#7AD8D3"            
android:text="Forget password"  

android:style="?android:attr/borderlessButtonStyle"    

android:textColor="#ffffff" />

欢迎提出任何建议。

【问题讨论】:

    标签: xamarin xamarin.android


    【解决方案1】:

    使用材料设计中的平面按钮来获得无边框按钮。

    http://www.materialdoc.com/flat-button/

    <Button
        android:id="@+id/ForgetPwd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Forgot Password?"
        style="@style/Widget.AppCompat.Button.Borderless"/>
    

    我认为您不能仅使用 xml 在按钮文本上添加下划线。您可以使用以下代码实现它

    Button forgetPwdButton = FindViewById<Button>(Resource.Id.ForgetPwd);
    forgetPwdButton.PaintFlags = forgetPwdButton.PaintFlags | Android.Graphics.PaintFlags.UnderlineText;
    

    【讨论】:

    • 我把这个:style="@style/Widget.AppCompat.Button.Borderless" 放在 Button XML 中,我去这个 ErrMsg: style 属性没有声明
    • 通过 nuget 将 Xamarin.Android.Aupport.V7.Appcompat 包添加到您的项目并重新构建。
    • 我添加了这个 android:background="#ffffff" 并带走了 style="@style/Widget.AppCompat.Button.Borderless" 并使用您的代码绘制下划线。它以这种方式工作。至于风格,这个@style/widget是内置的吗? Xamarin 似乎无法识别它。
    • 也是为什么即使我使用了这个文本,字母都是大写的:android:text="Forgot Password"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-07
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    • 2019-11-05
    相关资源
    最近更新 更多