导航:首页 > 编程语言 > 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代码相关的资料

热点内容
任命文件人字多少号 浏览:27
如何给桌面的文件自动填写序号 浏览:349
压缩文件JPG重命名 浏览:487
vivox7怎么隐藏文件 浏览:340
官网买苹果好处 浏览:153
直播app源码如何搭建 浏览:31
c盘系统文件包介绍图片 浏览:856
linuxopt主要存哪些文件 浏览:924
jsdate天数 浏览:930
qq空间怎样发视频文件在哪里找 浏览:208
nrf2401收发程序 浏览:498
哪个网站看新闻最好 浏览:944
找到文件夹并清除linux 浏览:82
苹果app不安全怎么办 浏览:1000
电脑桌面文件收集软件推荐 浏览:317
桌面的文件夹不能删除不了怎么办 浏览:724
什么是手机温控文件 浏览:840
广东农信app怎么更改预留手机号码 浏览:241
cdm打开隐藏文件夹 浏览:320
贝壳app房子为什么偶尔不显示 浏览:4

友情链接