A summary of some of the less common XML file attributes of Android

Source: Internet
Author: User
Tags rfc

Objective

In recent projects, XML has used some properties that might not normally be used too often, possibly involving androidmanifest.xml, layout layouts, or to specific controls!

Androidmanifest.xml

Add a tag in the Androidmanifest.xml file
<uses-sdk tools:overrideLibrary="xxx.xxx.aaa, xxx.xxx.bbb"/>
The xxx.xxx.xxx is a third-party library package name, and if there are multiple libraries, separate them with commas. This is done so that the minimum version limit can be ignored for androidmanifest.xml in the project and for Androidmanifest.xml merging of third-party libraries.

<application android:allowBackup="false">
Whether to allow backup of the app's data, the default is true, and when the data is backed up, its data is backed up. If set to False, the app's data will never be backed up, even if the entire system is backed up.

<application android:supportsRtl="true">
Android now offers some APIs that allow you to build a more elegant user interface for transforming the layout direction. These interfaces will support right-to-left (RTL) languages and reading directions. such as Arabic and Hebrew.
In order for your app to support RTL layouts, you need to set the element's Android:supportsrtl property to "true" in the manifest file. Once enabled, the system will enable a variety of RTL APIs to display your app in RTL layouts.
If this attribute is used, there are several issues to note:
1. Requires a minimum SDK version number of 17.
2. Change the left-to-right layout property to the start-end direction of the layout property.

<application tools:replace="android:icon,android:label,android:name">
The Gradle plugin for as is enabled by default with the manifest merger Tool, and if the same properties as the master project are defined in the library project (such as the default generated Android:icon and Android:theme), then the merge fails with an error.
You will need to add the above attribute to the manifest.xml.

<service    android:enabled="true"    android:exported="true" />

The enabled property indicates whether the service can be instantiated by the system. True if available, false otherwise. The default is true. The <application> element has its own enabled property that can be applied to all application components, including services. If the service is enabled, both this <application> and the <service> property must be true (they are all default values). If there is a false, the service will be disabled; it will not be instantiated.
The exported property indicates whether other application components can invoke the service or interact with it, or false if it is true. When the value is false, only the component of the same app or an app with the same user ID can start the service or bind it.
The default value depends on whether the service contains intent filters. The absence of a filter means that it can only be called by specifying its exact class name. This means that the service can only be used inside the app (because other apps don't know the class name). Therefore, in this case, the default value is False. On the other hand, at least one filter means that the service can be used externally, so the default value is true.

<activity     android:excludeFromRecents="true"     tools:ignore="ExportedActivity">

The Excludefromrecents property indicates that the control is not displayed in the recent list. True when not displayed; false displays, default.
Tools:ignore= "exportedactivity" means that all apps are allowed to use it.

The data label under ⑦intent-filter

<data android:mimetype="*/*" /><data android:scheme="file" /><data android:host="*" /><data android:path="*"/><data android:pathprefix="*"/><data android:port="*"/><data android:pathpattern=". *. *.. *.. *.. *.vpn " />

This tag element is used to add a data specification to a intent filter, which can be a data type (MimeType attribute), a data location identifier (URI), or a data type and a data location identifier (URI). A URI (in the following format) is separated into several separate properties to specify:
scheme://host:port/path or pathPrefix or pathPattern
These properties are optional, but are also interdependent. If the scheme attribute is not specified for the intent filter, all other URI properties are ignored. If you do not specify a host property for the filter, the Port property and all path properties are ignored.
All data elements contained in the same Intent-filter element will only work on the filter.

MimeType
Multi-purpose Internet Mail Extension (mime,multipurpose), which is used to tell the Android system what type of file the activity can handle.
Format: [Type]/[subtype]
The type has the following form:

Text:用于标准化地表示的文本信息,文本消息可以是多种字符集和或者多种格式的;Multipart:用于连接消息体的多个部分构成一个消息,这些部分可以是不同类型的数据;Application:用于传输应用程序数据或者二进制数据;Message:用于包装一个E-mail消息;Image:用于传输静态图片数据;Audio:用于传输音频或者音声数据;Video:用于传输动态影像数据,可以是与音频编辑在一起的视频数据格式。

The subtype is used to specify the detailed form of the type. The set of Content-type/subtype pairs and the associated parameters will grow over time. To ensure that these values are developed in an orderly and public state, MIME uses the internet Assigned Numbers Authority (IANA) as the central registration mechanism to manage these values. The common subtype values are as follows:

text/plain(纯文本)text/html(HTML文档)application/xhtml+xml(XHTML文档)image/gif(GIF图像)image/jpeg(JPEG图像)【PHP中为:image/pjpeg】image/png(PNG图像)【PHP中为:image/x-png】video/mpeg(MPEG动画)application/octet-stream(任意的二进制数据)application/pdf(PDF文档)application/msword(Microsoft Word文件)message/rfc822(RFC 822形式)multipart/alternative(HTML邮件的HTML形式和纯文本形式,相同内容使用不同形式表示)application/x-www-form-urlencoded(使用HTTP的POST方法提交的表单)multipart/form-data(同上,但主要用于表单提交时伴随文件上传的场合)

Host
This property user defines the host portion of the URI authorization, which is meaningless unless the filter also specifies the <data> scheme attribute of the element.
Note: In the Android framework, the host name match is case-sensitive and is not the same as the RFC format. Therefore, always use lowercase letters to specify the host name.

Path/pathprefix/pathpattern
This three attribute is used to specify the path portion of a URI. The Path property specifies a complete path that matches the path in the intent object. The Pathprefix property specifies only a partial path, which matches the initial part of the path in the intent object. The Pathpattern property specifies a full path to match the path in the intent object, but the path can contain the following wildcard characters:
1. Asterisk wildcard characters, the * asterisk in the path represents the character before any number of asterisks, such as a* A, AA, AAA, AAAA 、... String matches.
2. A combination of dot and asterisk .* wildcard, which can match any string, such as. *html, can be abchhtml, cHTML, HTML, dssf.html 、... such as string matching.

Because the system reads the string from the XML, it takes the ’\’ symbol as a forced escape character, so it needs to be escaped two times. For example, symbols are ”*” written ”\\*” and symbols are ’\’ written ”\\\\” . This is basically the same as in Java code.

Port
This property is used to define the port portion of the URI authorization. This property makes sense only when the scheme and the host property are specified for the filter.

Scheme
This property is used to set the scheme portion of the URI. It is the most basic property set for the specified URI, at least one scheme property is set for the filter, otherwise the other URI attribute is meaningless.
The scheme attribute value does not end with a ":" sign (such as HTTP, not http:)
If the filter has a data type (set the MimeType property), but the scheme attribute is not set, then the system assumes that scheme is content: and file:
Note: In the Android framework, scheme matches are case-sensitive and not the same as RFC format. Therefore, always use lowercase letters to specify scheme.

<meta-data/> Label
Meta-data, like its name, is used primarily to define some component-related configuration values.
By official definition, metadata is a set of name-value pairs (Name-value pair) that are used by the parent component, so the corresponding meta-data element should be defined in the corresponding component. That is, if you want to use metadata in activity, then meta-data must be defined in Androidmanifest.xml's activity statement.
Use:

<meta-data    android:name="com.yt.key"    android:value="@string/value" />

Then get our values in the code:

//In the Activity app <meta-data> elements. Activityinfo info = This. Getpackagemanager (). Getactivityinfo (Getcomponentname (), packagemanager.get_meta_data); Info.metaData.getString ("Meta_name");//In application applications <meta-data> elements. ApplicationInfo AppInfo = This. Getpackagemanager (). Getapplicationinfo (Getpackagename (), packagemanager.get_meta_data); AppInfo.metaData.getString ("Meta_name");//In service apps <meta-data> elements. ComponentName cn =NewComponentName ( This, Metadataservice.class); ServiceInfo info = This. Getpackagemanager (). GetServiceInfo (CN, Packagemanager.get_meta_data); Info.metaData.getString ("Meta_name");//In receiver applications <meta-data> elements. ComponentName cn =NewComponentName (context, metadatareceiver.class); Activityinfo info = Context.getpackagemanager (). Getreceiverinfo (CN, Packagemanager.get_meta_data); Info.metaData.getString ("Meta_name");
Layout.xml① adding Tools:context to a layout or control
< LinearLayout  xmlns:android  = "HTTP +/ Schemas.android.com/apk/res/android " xmlns:tools  =     "Http://schemas.android.com/tools"  android:layout_width  = "match_parent"  android:layout_height  = "match_parent"  android:orientation  =" vertical " tools:context  =;   

tools:context="activity name"This sentence will not be packaged into the APK. Just the layout editor of ADT sets the corresponding render context in your current layout file , indicating that the rendering context of your current layout is the activity that the activity name corresponds to. If the activity has a theme set in the manifest file, the ADT Layout Editor will render your current layout based on this theme. That is, if you set the mainactivity set a theme.light (others can also), then you see in the visual layout manager of the background of a control ah or something should be theme.light look. Just to show you what you see and what you get.

② Abstract Layout Labels

Use abstract layout labels (include, viewstub, merge) primarily to optimize layouts! , removing unnecessary nesting and view nodes, and reducing unnecessary infalte and other layout-related benefits.

<include/>Label

The include tag is often used to extract the public part of the layout for other layouts to be shared for layout modularity, which is convenient for layout authoring.
Usage:
<include layout="@layout/title.xml" />
The only attribute required by the include tag is the Layout property, which specifies the layouts files that need to be included. You can define the Android:id and Android:layout_* properties to override the corresponding property values that are introduced into the layout root node.

<viewstub/>Label

The viewstub tag can be used to introduce an external layout as well as an include tag, but the layout introduced by Viewstub does not expand by default, which saves both the display and the location, saving CPU and memory when parsing layout.
Viewstub is often used to introduce layouts that are not displayed by default, only in special cases, such as progress layouts, refresh layouts for network failures, prompt layouts for information errors, and so on.
Usage:

<ViewStub        android:id="@+id/layout_error"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout="@layout/network_error" />

Where Network_error.xml is the layout that needs to be displayed only when a network error occurs, the default is not resolved.
When we want to use, there are two ways to use, the effect is the same:

((ViewStub) findViewById(R.id.layout_error)).setVisibility(View.VISIBLE);  // 或者 View importPanel = ((ViewStub) findViewById(R.id.layout_error)).inflate();  
<merge/>Label

The use of include may result in too many layouts nesting, unnecessary layout nodes, resulting in slow parsing, unnecessary nodes and nesting can be viewed through the hierarchy Viewer or settings--developer options, display layout boundaries. The merge tag plays a very important role in the structure optimization of the UI, and it can prune unnecessary layers and optimize the UI.
Merge is used to replace framelayout or when one layout contains another, the Merge tab eliminates the extra view groups in the view hierarchy.

The Merge tab can be used in two typical cases:
A. the top node of the layout is framelayout and does not need to set properties such as background or padding, which can be replaced with merge because the parent view of the activity content view is a framelayout. So you can use merge to eliminate only one left.
B. when a layout is used as a sub-layout by another layout include, use merge as the top node of the layout, so that the top nodes are automatically ignored when they are introduced, and all of their child nodes are merged into the main layout.

Usage:

<?xml version="1.0" encoding="utf-8"?><merge xmlns:android="http://schemas.android.com/apk/res/android">      <!--具体的布局内容-->    </merge>
Control

①textview

<!--设置文字的外观,这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观-->android:textAppearance="?android:attr/XXXX"<!--设置文字过长时,该如何显示,"start"—–省略号显示在开头;"end"——省略号显示在结尾;"middle"—-省略号显示在中间;"marquee" ——以跑马灯 的方式显示(动画 横向移动)-->android:ellipsize="start"<!--设置字形,如bold粗体,italic倾斜-->android:textStyle="bold"

②edittext

android:imeActionId="@+id/login"android:imeActionLabel="@string/sign_in"android:imeOptions="actionUnspecified"

These three properties are set on the function of the ENTER key in the lower right corner of the soft keyboard, and then override the Oneditoraction () method in the code, and the ActionId in the parameter corresponds to the value set in the Imeoption property.

<!--设置EditText光标的颜色,如果为@null,则设置成与文字颜色一样-->android:textCursorDrawable="@null"

A summary of some of the less common XML file attributes of Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.