您现在的位置: 首页 > 网站导航收录 > 百科知识百科知识
attributeset(Android的AttributeSet是什么?)
图像,资源,字符串attributeset(Android的AttributeSet是什么?)
发布时间:2020-12-06加入收藏来源:互联网点击:
复制代码
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
复制代码
查看MenuInflater.inflate(int,Menu)
复制代码
/**
* Inflate a menu hierarchy from the specified XML resource.
*
* @param menuRes Resource ID for an XML layout resource to load (e.g., codeR.menu.main_activity/code)
* @param menu The Menu to inflate into. The items and submenus will be added to this Menu.
*/
public void inflate(int menuRes, Menu menu) {
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(parser, attrs, menu);
} catch ...finally {
if (parser != null) parser.close();
}
}
复制代码
14.样式与主题(style/theme)
1.样式style
android中样式和css中样式作用是一样的,都是用于为界面元素定义显示风格,它是一个包含一个或者多个控件属性的集合。
定义样式需要在res/values/styles.xml中进行定义,如下是一个样式的定义:
style name="textViewStyle"
item name="android:textSize"22sp/item
item name="android:textColor"#FF0000/item
/style
style name="textViewStyle1" parent="textViewStyle"/style!-- 此样式继承自textViewStyle --
style name="textViewStyle.Livingstone"!-- 样式继承的另一种写法,但不可用此写法继承Android自带的定义样式? --
item name="android:textColor"#00FF00/item
/style
所有定义的样式都会在R文件中自动生成一个资源ID,加一个点表示样式继承会生成上图所示的资源id;
样式的引用:
TextView
style="@style/textViewStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="hello" /
2.主题Theme
主题应用于整个应用或者activity,样式应用于具体的控件上。主题的应用与样式定义一样,不同的是主题还可以设置窗口的显示风格;主题的引用需要在清单文件中进行引用,如引用到整个应用之上就需要在Application节点中进行配置引用,而引用到单个Activity只需要在此Activity中进行配置引用;
复制代码
style name="Livingstonetheme"!--此定义是一个无Title的主题--
item name="android:windowNoTitle"true/item
item name="android:windowFullscreen"?android:windowNoTitle/item
!-- 问号表示引用此主题中android:windowNoTitle属性的值 --
item name="android:textSize"18sp/item
/style
复制代码
android系统定义了一些属性,如android:theme="@android:style/Theme.Dialog",该主题可以让Activity看起来像一个对话框,更多主题可以在文档reference-android-R.style中查看。当主题里面的样式属性值与样式里面的属性值发生冲突的时候会显示样式里面的值;
15.其它资源
在资源文件中还可以包括尺寸(dimen)、整数(integer)、布尔(bool) 、整形数组资源(integer-array)、资源数组(array)、颜色(color)
TypedArray ta = getResources().obtainTypedArray(int id); // 获取数组资源,包括integer-array、array
Final总结:
除了res/values目录中的资源名,其它目录的资源都会以文件名在R类的相应子类中生成变量;而res/values中的资源会以name属性值为变量名在R类的相应子类中生成变量;
以上就是attributeset的相关信息介绍,希望能对大家有所帮助。
本文到此结束,希望对大家有所帮助呢。
上一篇:无题诗(《无题》全诗)
下一篇:返回列表
相关链接 |
||
网友回复(共有 0 条回复) |