栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Android按钮样式化编程

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android按钮样式化编程

让我们为您编写一些案例代码::)为了动态地将样式应用于视图(在这种情况下为按钮),您必须在布局文件夹(res / layout)中执行以下操作。

我将其命名为 buttonstyle.xml

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_pressed="true">        <shape> <solid android:color="#449def"/> <stroke android:width="1dp" android:color="#2f6699"/> <corners android:radius="3dp"/> <padding android:left="10dp" android:top="10dp" android:right="10dp"          android:bottom="10dp"/>        </shape>    </item>    <item>        <shape> <gradient android:startColor="#449def" android:endColor="#2f6699" android:angle="270"/> <stroke android:width="1dp" android:color="#2f6699"/> <corners android:radius="4dp"/> <padding android:left="10dp" android:top="10dp" android:right="10dp"          android:bottom="10dp"/>        </shape>    </item></selector>

现在将样式应用于按钮,将以下代码添加到活动的onCreate()方法中。

Button transferBtn = new Button(this);transferBtn.setText("Test Example");transferBtn.setId(R.string.transferBtn);transferBtn.setBackgroundResource(R.layout.buttonstyle);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/428234.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号