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

安卓styleparent

发布时间:2024-09-13 07:51:14

A. 安卓编程怎样自定义menu中的字体大小

一、先到AndroidManifest.xml看看当前的theme是什么:

比如我这里的是AppTheme

[html] view plain
<application
......
android:theme="@style/MyAppTheme" >

二、然后在资源文件的res/values/styles.xml中找到 你的主题:

[html] view plain
<style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">

三、然后在此添加上一个item,name=android:actionMenuTextAppearance,然后引用你自己定义的文字样式,不管是大小还是颜色都可以自己定义

[html] view plain
<style name="MyAppTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionMenuTextAppearance">@style/MyMenuTextStyle</item>
</style>

<style name="MyMenuTextStyle">
<item name="android:textColor">@android:color/red</item>
<item name="android:textSize">16sp</item>
</style>

B. 如何修改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);
}
}

C. 安卓开发Layout XML 下出现这种警告怎么解决

鼠标点到黄色来敬告上自就会弹出提示了嘛,类似于这种“
Buttons in button bars should be borderless; use style="?
adt的版本越来越高了,所以也要求规范了,一些属性官方要求是要写上的,比如style等,早期android1.5、1.6的时候就没这么多要求,可能随后发展这些属性不写就不是黄色警告了,就变红色错误了。
解决的方式是给每一个button或者其他控件加上style样式。

阅读全文

与安卓styleparent相关的资料

热点内容
在哪里可以下载书痴APP 浏览:644
橡皮擦工具怎么使用方法 浏览:781
appstore余额充话费 浏览:227
struts2验证文件 浏览:198
小米6app消息变成蓝色是什么情况 浏览:487
如何通过修改网站源代码获取会员 浏览:189
发文件一般用多少号字符 浏览:99
ps保存文件时提示文件已使用 浏览:625
什么版本win7好用 浏览:589
如何复制plc编程 浏览:55
缺少什么样的网站 浏览:890
建一个私彩网站多少钱 浏览:614
黑苹果固态硬盘驱动程序 浏览:61
u盘文件过大不能复制 浏览:901
谷歌浏览器49版本 浏览:978
xp系统网络故障提示码错误651 浏览:360
打开文件夹是有声音了 浏览:539
图片怎么样用文件夹发送 浏览:370
苹果5屏幕跟波浪一样 浏览:611
手机app违规到哪里举报 浏览:799

友情链接