Use of preference tags in android

Source: Internet
Author: User

Now do the company task, often to read settings source code, and then found in the XML file is almost entirely used in Preferencescreen and preferencecategory tags, very few useful layout and control, Then I went online to read a lot of relevant information, in this summary.

First, in the Res directory, create a new folder named XML, then create a aaa.xml file and select the resource tag.

Use Preferencecategory first, the code is as follows

1 <preferencecategoryAndroid:title= "show a row of preferences" >2         <checkboxpreference3             Android:key= "Checkbox_pre"4 android:summary= "This is a switch button"5 Android:title= "Switch Preference" />6     </preferencecategory>

Preferencecategory is equivalent to grouping, placing the same class of options in the same area.

Take a look at Preferencescreen, the code is as follows

1 <Preferencescreen2             Android:key= "Screen_pre"3 android:summary= "Show another preference screen"4 Android:title= "Screen" >5             <checkboxpreference6                 Android:key= "Next_screen_checkbox_pre"7 android:summary= "Another on-screen preference"8 Android:title= "Switch Preference" />9         </Preferencescreen>

, and then find no checkbox to show

Because Preferencescreen can be clicked in, click on the option, you can see the checkbox.

Then look at listpreference, generally embedded in the preferencescreen used, looks comfortable, the code is as follows

<PreferencescreenAndroid:title= "dialog-based preferences" > <listpreferenceAndroid:dialogtitle= "Select one"android:entries= "@array/auto_update_frequency_entry"android:entryvalues= "@array/auto_update_frequency_value"Android:key= "List_pre"android:summary= "Use a list dialog box"Android:title= "List Preference" >        </listpreference></Preferencescreen>

Clicking on the screen,listpreference will pop up like Dialog,

Android:entries and Android:entryvalues Two properties of the value source:

Create a array.xml in the values directory

<?XML version= "1.0" encoding= "Utf-8"?><Resources>    <String-arrayname= "Auto_update_frequency_entry">        <Item>10 minutes</Item>        <Item>30 minutes</Item>        <Item>1 hours</Item>        <Item>12 hours</Item>        <Item>24 hours</Item>    </String-array>    <String-arrayname= "Auto_update_frequency_value">        <Item>10</Item>        <Item>30</Item>        <Item>60</Item>        <Item>720</Item>        <Item>1440</Item>    </String-array></Resources>

I'm probably going to get to know this right now.

Use of preference tags in android

Related Article

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.