. Net Moving Android 4.4 Daily notes (4)--button events and internationalization

Source: Internet
Author: User

Original:. Net moving Android 4.4 Daily notes (4)--button events and internationalization

We know that resources are registered to R.java we can read the components in the interface through R.java. As with our. NET, the component is read by ID

Knowledge Points:

    1. Reading components via R.java
    2. Mainactivity.java finding components by Findviewbyid method
    3. Using @string to find strings in layout, this is a basic acquaintance with the internationalization of our MVC, and we switch between Chinese and English through the resource reference of XML.
    4. Join Chinese and English localization

Double-click Fragment_main.xml Design view, drag a button and a TextView, and double-click into the XML code

Add Android:onclick, I also rely on guessing, program code has similarities, especially Java and JavaScript. But we're better off looking for help documents.

Input android:onclick= "Settextview"

So this is like JavaScript, there must be a Settextview method in the background to listen to this event

Open our Mainactivity.java Join method

 Public void Settextview (View v)    {        TextView TV=(TextView) Findviewbyid (r.id.textview1);        Tv.settext ("Click on the button I'm going to change!") ");    }

Run to look at the effect, made a lable font settings like nothing to show off

Ok. Now let's see how to switch between the Chinese and English versions!

Our button name is buttons, when the mobile phone system is set to Chinese, it should be the words of the pushbutton, the English time display button

Now open res-----values----String.xml Add a property (here equals. NET internationalized Res resource file. XML with the corresponding health value)

<?xml version= "1.0" encoding= "Utf-8"?><resources>    <string name= "App_name" >helloworld</ string>    <string name= "Hello_world" >hello world!</string>    <string name= "Action_ Settings ">Settings</string>    <string name=" Btn_name ">Button</string></resources>

<string name= "Btn_name" >Button</string>

In the values Create folder VALUES-ZH-RCN and copy the values under the String.xml to VALUES-ZH-RCN button to change buttons

<?xml version= "1.0" encoding= "Utf-8"?><resources>    <string name= "App_name" >helloworld</ string>    <string name= "Hello_world" >hello world!</string>    <string name= "Action_settings" >Settings</string>    <string name= "Btn_name" > Buttons </string></resources>

Back to layout, change the button's text from button to @string/btn_name.

In fact, the @ here is the meaning of R. That is R.string.btn_name we can open R.java and observe btn_name.

Run and open the version of the switching system run the Customlocale switch inside the simulator

. Net Moving Android 4.4 Daily notes (4)--button events and internationalization

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.