A summary of resource file usage examples for Android development _android

Source: Internet
Author: User

This example summarizes the use of resource files for Android development. Share to everyone for your reference, specific as follows:

Here are a few of the things that are often used in Android development

Arrays.xml definition Array

Cases:

<resources>
  <!--share items--> 
  <string-array name= "App_share_items" >
    <item> Sina Weibo </item>
    <item> Tencent micro-blog </item>
  </string-array> 
</resources>

Solid rounded background

<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
  <solid android:color= "#4a90e2" >
  <corners android:radius= "95DP"/>
</shape>

Usage:

android:background= "@drawable/xml_background_button_blue"

The type to get this background is: drawable:gradientdrawable, we can change its color, and keep the background unchanged.

Color related

PS: 0 Transparent, 1 completely impervious
Android: Color format: ARGB alpha:[0,255] completely transparent to completely opaque
Pink: #8f0f

Uses-permission

When you play the window, add in manifest:

<uses-permission android:name= "Android.permission.SYSTEM_ALERT_WINDOW"/>

Correspondence between resource files and classes

Selector corresponds to StateList.

<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android=
"http://schemas.android.com/apk/res/" Android >
  <item android:state_pressed= "true" android:drawable= "@drawable/xml_login_button_press"/>
  <item android:drawable= "@drawable/xml_login_button_normal"/>
</selector>

<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
  <item android:state_pressed=" true ">
    <shape>
      <solid android:color=" @color /pressed_color "/>
    </shape>
  </item>
  <item>
    <shape>
      <solid Android:color= "@color/transparent"/>
    </shape>
  </item>
</selector>

The shape corresponds to the gradientdrawable.

<?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
  <solid android:color=" #4a90e2 "/>
  <corners android:radius=" 95DP "/>
</ Shape>

Notification

1. Action associated with activity

The following two steps are indispensable
step1: Specify an Action constant:

public static final String Download_manager = "Com.james.app.download";

step2: Specify the corresponding intentfilter in the corresponding activity

<intent-filter>
  <action android:name= "com.james.app.download"/>
  <category android:name= " Android.intent.category.DEFAULT "/>
</intent-filter>

2. The notification is distinguished by action, not by ID.

For more information on Android-related content readers can view the site topics: "Android Resource Operation tips Summary", "Android Development introduction and Advanced Course", "Android Control Usage Summary", "Android SMS and telephone operating skills summary" and " Android Multimedia How-to Summary (audio, video, recording, etc.)

I hope this article will help you with the Android program.

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.