当前位置:首页 » 安卓系统 » androidstyle文件

androidstyle文件

发布时间: 2022-08-19 06:04:41

Ⅰ android 为什么在style.xml文件里的其中一个style中的item前面随便加个符编译号不报错

因为html很宽容,安卓支持html,只有你大概语法没有错误,一般都能编译成功。

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

Style是View中一些属性的集合,包括height,padding,fontcolor,background等等,Style单独定义在xml文件中,类似与web页面中css的角色,将设计和内容分开,便于修改和重复使用。

1 定义Style

style文件需要保存在res/values目录下,文件名任意,但是必须是xml文件,sytle文件的根标记必须是<resources>。写了一个简单示例,效果如下:

请参考android学习手册,例子、源码、文档全部搞定,采用androidstudo的目录结构,360手机助手中下载。下面是截图。

main.xml文件代码:

<?xmlversion="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<TextView

style="@style/CodeFont"

android:text="测试style">

</TextView>

</LinearLayout>

声明style是CodeFont,对应的是style文件中的style name。mystyle.xml文件中定义了style name是CodeFont:

parent属性表示style之间可以继承,同时可以覆盖parent style的一些属性。

<?xmlversion="1.0" encoding="utf-8"?>

<resources>

<style name="CodeFont"parent="@android:style/TextAppearance.Medium">

<itemname="android:layout_width">fill_parent</item>

<itemname="android:layout_height">wrap_content</item>

<itemname="android:textColor">#00FF00</item>

<itemname="android:typeface">monospace</item>

</style>

</resources>

2 Style的继承

style继承有两种方式:

style的继承可以通过parent属性,用来继承android已经定义好的style,例如:

<style name="GreenText" parent="@android:style/TextAppearance">

<itemname="android:textColor">#00FF00</item>

</style>

继承了android中的TextAppearance,同时覆盖了android:textColor属性。

如果要继承自定义的style,不需要通过parent属性,只要style的name以需要继承的style的name开始后跟新的style的name,中间用“.”隔开。注意:这种方式只适用与自定义的style继承。

<style name="CodeFont.Red">

<itemname="android:textColor">#FF0000</item>

</style>

新的style继承了CodeFont,则在修改上边例子中的main.xml为:

<?xmlversion="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<TextView

style="@style/CodeFont.Red"

android:text="测试style">

</TextView>

</LinearLayout>


style也可以多级继承:

<stylename="CodeFont.Red.Big">

<itemname="android:textSize">30sp</item>

</style> sytle的更多属性见android包下的R.attr。需要注意,并不是所有的View都支持定义的style的属性,如果自定义的sytle中包含View不支持的属性,程序会自动忽略它。

Ⅲ android怎样写style

在values文件夹下的styles中添加类似
<style name="Button_style" >
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">18sp</item>
<item name="android:singleLine">true</item>
<item name="android:ellipsize">marquee</item>
<item name="android:gravity">center</item>
</style>
中间的item可以自己添加想要的效果
然后在Button中属性添加style="@style/Button_style"!

Ⅳ 如何在android style文件中使用自定义属性

在android style文件中使用自定义属性是为了方便,只需要这里写一次就可以在布局文件中多次调用,使用方法如下图:

1、首先使用android studio打开一个项目,如下图:

Ⅳ Android中style和theme的区别

Theme 和Style资源,将一些通用的属性提取出来,方便使用。

相同:
Theme和Style位于values文件夹下styles.xml下,格式相同。

[java] view plain
<style name="MyTransparent">
<item name="android:windowBackground">@color/transparent_background</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>
<item name="Android:windowNoTitle">?android:windowIsTranslucent</item>其中 问号表示引用本主题中已经定义过的资源的值。

在需要使用的时候调用

[java] view plain
<EditText
android:id="@+id/nameEdit"
<span style="color:#ff0000;"> style="@style/LoginOrRegisterEditStyle"</span>
android:hint="@string/input_real_name"
android:layout_below="@id/tipHead"
android:layout_marginTop="20dp" />

不同:
Theme在AndroidManifest.xml中德Application节点或者Activity节点设置android:theme,或者在对应Activity中通过代码设置setTheme(),影响整个应用或者一个Activity.
Style一般是在布局中的View中设置。影响单个View,如EditText,TextView等等。

如果主题和样式属性有冲突,样式的属性高于主题。

如果需要使用系统自带的主题

[java] view plain
android:theme=<span style="color:#ff0000;">"@android:style</span>/Theme.Light.NoTitleBar"

Ⅵ Android TextView怎么引用Style

在android style文件中使用自定义属性是为了方便,只需要这里写一次就可以在布局文件中多次调用,使用方法如下图:

1、首先使用android studio打开一个项目,如下图:

Ⅶ Android 动态创建View,是否可以使用 style,如何使用

Android 是可以使用 style的,具体方法为:
1、在Android中可以这样定义样式:
在res/values/styles.xml文件中添加以下内容
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name=“itcast”>
<item name="android:textSize">18px</item>
<item name="android:textColor">#0000CC</item>
</style>
</resources>
2、在layout文件中可以像下面这样使用上面的android样式:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ....>
<TextView style="@style/itcast"
..... />
3、可以使他继承父样式,当然,如果父样式的值不符合需求,你也可以对它进行修改,如下:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="itcast">
<item name="android:textSize">18px</item>
<item name="android:textColor">#0000CC</item>
</style>
<style name="subitcast" parent="@style/itcast">
<item name="android:textColor">#FF0000</item>
</style>
</resources>

热点内容
诺基亚密码忘了打什么电话 发布:2024-09-17 03:27:09 浏览:555
树深度优先算法 发布:2024-09-17 03:26:58 浏览:472
跳转页源码 发布:2024-09-17 03:13:05 浏览:543
html文件上传表单 发布:2024-09-17 03:08:02 浏览:785
聊天软件编程 发布:2024-09-17 03:00:07 浏览:726
linuxoracle安装路径 发布:2024-09-17 01:57:29 浏览:688
两个安卓手机照片怎么同步 发布:2024-09-17 01:51:53 浏览:207
cf编译后没有黑框跳出来 发布:2024-09-17 01:46:54 浏览:249
安卓怎么禁用应用读取列表 发布:2024-09-17 01:46:45 浏览:524
win10设密码在哪里 发布:2024-09-17 01:33:32 浏览:662