导航:首页 > 编程语言 > androidstyle代码

androidstyle代码

发布时间:2023-08-18 04:38:32

1. android 可以在程序代码中设置style吗

如果你是给textView的话,可以

textView.setTextAppearance(this, R.style.MyStyle);

其它的话就不行了。

2. android怎样写style

<style name="button_style">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginLeft">20dp</item>
<item name="android:layout_marginRight">20dp</item>
<item name="android:background">@drawable/button_click</item>
</style>

在res/values/styles 下边 类似这样写 就可以 调用的话 style="@style/button_style"
记得 已经在 style中写的东西 不要在button 下出现。不然会报错误


<Button
android:id="@+id/addLessonBtn"
style="@style/button_style"
android:text="@string/add_course_add" />

3. android中怎么创建style

自定义样式方法,可以直接通过定义xml文件来实现不同的样式:
只需要修改button_style文件,同样三种状态分开定义:
Xml代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient android:startColor="#0d76e1" android:endColor="#0d76e1"
android:angle="270" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="2dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>

<item android:state_focused="true">
<shape>
<gradient android:startColor="#ffc2b7" android:endColor="#ffc2b7"
android:angle="270" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="2dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>

<item>
<shape>
<gradient android:startColor="#000000" android:endColor="#ffffff"
android:angle="180" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="5dip" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>
</selector>

gradient 主体渐变 startColor开始颜色,endColor结束颜色 ,angle开始渐变的角度(值只能为90的倍数,0时为左到右渐变,90时为下到上渐变,依次逆时针类推)
stroke 边框 width 边框宽度,color 边框颜色
corners 圆角 radius 半径,0为直角
padding text值的相对位置

阅读全文

与androidstyle代码相关的资料

热点内容
vb编程器有什么用 浏览:999
excel如何分列数据与文字 浏览:884
512网络病毒 浏览:994
java调用google地图api接口 浏览:726
文件管理图片小窗 浏览:599
显卡数据怎么设置 浏览:557
无法创建cad图纸集文件 浏览:788
纸质文件转换电子版 浏览:807
矩阵键盘扫描程序原理 浏览:986
怎么开发高级编程 浏览:530
政府的拆迁红头文件在哪里找 浏览:600
xp串口工具 浏览:469
反射javaforname区别 浏览:249
java添加计时器和图片 浏览:452
shell编辑文件内容 浏览:614
u盘驱动在哪个文件夹里 浏览:938
华为手机跟苹果手机怎么克隆app 浏览:172
cad文件为什么显示文件名是否正确 浏览:174
程序配置文件能自动转换成txt 浏览:985
r4烧录卡不同版本 浏览:962

友情链接