Android Notes-1

Source: Internet
Author: User

1. Click the button to appear in the small window (response event)

How to configure:

Activity_main.xml file: <button (input) android:onclick= "Test1"/>

In the Mainactivity.java file:

public void test1 (view view) {

Toast.maketext (Mainactivity.this, "Contents of small Window", toast.length_shcrt (length of time shown)). Show ();

}

With each click, the button moves to the right 10 units (code below):

Dynamic mode:

Reusable mode (when multiple buttons are used to demonstrate their advantages):

Compare with HTML: Click Generate Small window

<script>

function test () {alert (123); }//Alert ("string");

</script>

<button onclick= "Test ()" > Test </button>

2. Click Toggle content, character address definition

Activity_main.xml file: <button (input) android:onclick= "Test2"/>

In the Mainactivity.java:

public void test2 (view view) {

Textview Textview = (Textview) Findviewbyid (R.ID.VIEW1);

Textview.settext ("Click to toggle Content");

}

Contrast HTML: Click to toggle Content

<button onclick= "Test ()" >test</button>

<span id= "AB" > I am a label </span>

<script>

function Test () {

var Ab=document.getelementbyid ("AB");

ab.innerhtml= "button click!!!";

}

</script>

Strings.xml in the values file, you can define a generic string (<string name= "tag name" > String content </string>), Call its contents directly: r.string. Tag name, call and name for button: android:text= "@string/Tag name"

There are also strings.xml in the Values-zh-rcn file, as well as the ability to define a string that, when both define the same name but differ in language, selects the appropriate language based on the language selected by the system.

3. Setting the background

Steps:

<1>. Save the picture in the Res/drawable file will love, if there is no drawable folder, you can create your own

<2> in Activity_main.xml,

<RelativeLayout>

android:background= "@drawable/Picture name"//drawable as folder name

</RelativeLayout>

<3>: Run code, test.

Android Notes-1

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.