导航:首页 > APP软件 > 安卓stylexml

安卓stylexml

发布时间:2024-06-14 04:53:05

Ⅰ 如何修改Android App的样式风格

android中可以自定义主题和风格。风格,也就是style,我们可以将一些统一的属性拿出来,比方说,长,宽,字体大小,字体颜色等等。可以在res/values目录下新建一个styles.xml的文件,在这个文件里面有resource根节点,在根节点里面添加item项,item项的名字就是属性的名字,item项的值就是属性的值,如下所示:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
</resources>

style中有一个父类属性parent, 这个属性是说明当前的这个style是继承自那个style的,当然这个style的属性值中都包含那个属性中的,你也可以修改继承到的属性的值,好了,style完成了,我们可以测试一下效果了,先写一个布局文件,比如说一个TextView什么的,可以用到这个style的。这里我就写一个EditText吧。下面是布局文件:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/MyText"
android:text="测试一下下"/>
</LinearLayout>

说完了style,下面就说说Theme,Theme跟style差不多,但是Theme是应用在Application或者Activity里面的,而Style是应用在某一个View里面的,还是有区别的,好了,废话不多说,还是看代码吧。下面的是style文件:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
<style parent="@android:style/Theme" name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@drawable/icon</item>
<item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>

style中有一个父类属性parent, 这个属性是说明当前的这个style是继承自那个style的,当然这个style的属性值中都包含那个属性中的,你也可以修改继承到的属性的值,好了,style完成了,我们可以测试一下效果了,先写一个布局文件,比如说一个TextView什么的,可以用到这个style的。这里我就写一个EditText吧。下面是布局文件:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/MyText"
android:text="测试一下下"/>
</LinearLayout>

说完了style,下面就说说Theme,Theme跟style差不多,但是Theme是应用在Application或者Activity里面的,而Style是应用在某一个View里面的,还是有区别的,好了,废话不多说,还是看代码吧。下面的是style文件:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
<style parent="@android:style/Theme" name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@drawable/icon</item>
<item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>

可以看到这里写了一个继承自系统默认的Theme的主题,里面有3个属性,这里强调一下第三个属性的值的问题,这里打个问号,然后加前面的一个item的名字表示引用的是那个名字的值,也就是那个名字对应的图片。
然后我们在Manifest.xml里面的Application里面加一个Theme的属性,这个属性对应的就是我们上面写的Theme。
复制代码 代码如下:

<application android:icon="@drawable/icon" android:label="@string/app_name"
android:theme="@style/CustomTheme">
<activity android:name=".TestStyle"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

上面的代码没有标题栏,背景和fram都是我们设置的图片。当然也可以在代码中设置主题:
复制代码 代码如下:

package com.test.shang;
import android.app.Activity;
import android.os.Bundle;
public class TestStyle extends Activity {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.CustomTheme);
setContentView(R.layout.test_style);
}
}

Ⅱ Android婧愮爜鐨刣ata/res/values/style.xml涓鐨勭枒闂

琛ㄦ槑缁ф壙锛岄棶鍙凤紵琛ㄦ槑浜嗘垜浠寮曠敤鐨勮祫婧愮殑鍊煎湪褰撳墠鐨勪富棰樺綋涓瀹氫箟杩囷紝杩樻湁涓涓狜绗﹀彿锛岃〃鏄庝簡鎴戜滑搴旂敤鐨勮祫婧愭槸鍓嶈竟瀹氫箟杩囩殑鎴栬呭湪鍓嶄竴涓椤圭洰涓鎴栬呭湪Android 妗嗘灦涓瀹氫箟杩囩殑銆

Ⅲ Android椤圭洰涓璿alues-v11values-v14鏂囦欢澶圭殑style.xml鏄浠涔堜綔鐢锛

values-v11浠h〃鍦ˋPI 11+鐨勮惧囦笂锛岀敤璇ョ洰褰曚笅鐨剆tyles.xml浠f浛res/values/styles.xml,鍏朵腑API 11+浠h〃android 3.0 +銆

values-v14浠h〃鍦ˋPI 14+鐨勮惧囦笂锛岀敤璇ョ洰褰曚笅鐨剆tyles.xml浠f浛res/values/styles.xml锛屽叾涓瑼PI 14+浠h〃android 4.0 +銆



Ⅳ 为android程序设置统一的背景图

这么久了,还是给个明确答案吧
styles.xml:
<style name="AppTheme" parent="AppBaseTheme">

<!-- All customizations that are NOT specific to a particular API-level can go here. -->

<item name="android:windowAnimationStyle">@style/animationActivity</item>

<item name="android:windowBackground">@drawable/dt_bg</item>你自己的图片设置在这里

</style>

AndroidManifest.xml中版Application设置theme
<application

android:theme="@style/AppTheme" >
运行项目权便出现你想要的背景

阅读全文

与安卓stylexml相关的资料

热点内容
智能ai机器人需要什么编程 浏览:825
可控编程主要技术指标有哪些 浏览:271
数据分析回归需要什么条件 浏览:285
微信小程序按钮颜色 浏览:69
长江大学网课用什么app 浏览:431
华中系统图纸编程哪个刀好 浏览:38
地方债务数据在哪里查看 浏览:932
扫描文件怎么设置格式 浏览:957
苹果邮箱主机名填什么 浏览:630
多张图片同一个文件夹 浏览:798
win7怎么打开shs文件 浏览:481
怎么把文件夹做成iso 浏览:164
缤客网站上的房价怎么在哪里修改 浏览:406
单片机c51计数器实验代码 浏览:990
宏编程鼠标代表什么意思 浏览:753
别人捡到苹果6有用吗 浏览:829
word文件用wps打开 浏览:477
macbook修改文件格式软件 浏览:757
美版s7edge那个版本好 浏览:529
视频隐藏在文件夹里 浏览:144

友情链接