android – 按钮左右对齐的文本

android – 按钮左右对齐的文本,第1张

概述我在 Android开发方面很新,我需要你的帮助. 我需要左侧对齐的粗体文本按钮和右侧对齐的另一种不同字体(较小和不同颜色)的文本,如下所示: [**Name** john]//Name is bold and black// john is smaller and let's say blue 我在网上做了一个研究,但我找不到任何东西. 我试过了: this.button 我在 Android开发方面很新,我需要你的帮助.
我需要左侧对齐的粗体文本按钮和右侧对齐的另一种不同字体(较小和不同颜色)的文本,如下所示:

[**name**           john]//name is bold and black// john is smaller and let's say blue

我在网上做了一个研究,但我找不到任何东西.
我试过了:

this.button.setText(HTML.fromHTML(styledText));

但它看起来不适用于alignment =“right”,text-allign:right或者甚至
浮动:正确的.

我还找到了另一种使用表格布局和表格行的解决方案,但我需要一个按钮来触发一些动作.我不希望文本的两个部分有两个按钮.

提前致谢.

解决方法 第1步:res / drawable / button_selector.xml

<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID">    <item androID:drawable="@drawable/button_bg_pressed" androID:state_pressed="true"></item>    <item androID:drawable="@drawable/button_bg_normal"></item></selector>

第2步:使用两个TextVIEw创建一个linearLayout.

<linearLayout                androID:ID="@+ID/myCustombutton"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content"                androID:orIEntation="horizontal"                androID:background="@drawable/button_selector" >                <TextVIEw                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:gravity="left"                    androID:textStyle="bold"                    androID:textcolor="@color/black"                    androID:background="@drawable/ai_contact_us" />                <TextVIEw                    androID:ID="@+ID/airesetPwdbutton"                    androID:layout_wIDth="wrap_content"                    androID:layout_height="wrap_content"                    androID:gravity="right"                    androID:textcolor="@color/blue"/>            </linearLayout>

第3步:在你的onCreate()

VIEw buttonVIEw = findVIEwByID(R.ID.myCustombutton);buttonVIEw.setonClickListener(new VIEw.OnClickListenet(){    @OverrIDe    public voID onClick(VIEw vIEw) {    Toast.makeText(MainActivity.this,"button Clicked",Toast.LENGTH_SHORT).show();    }});
总结

以上是内存溢出为你收集整理的android – 按钮左右对齐的文本全部内容,希望文章能够帮你解决android – 按钮左右对齐的文本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1125207.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存