[Android] Development the next day

Source: Internet
Author: User

When using Android-studio, if you are not accustomed to the interface, you can find the topic you like on the http://color-themes.com/website free download and use the Android-studio menu File, Import Settings ... To use the downloaded theme.

In Android-studio, the project hierarchy is expanded by default on Android, as shown in. If you are not accustomed you can click on Android to switch.

The androidmanifest.xml is equivalent to the project properties, Activity_main.xml is equivalent to the interface properties, Strings.xml is where the various strings are stored.

Dingding the famous R.java file is not visible under this project display mode, can be found after switching to other display methods, or directly using the Explorer file search R.java to find it.

Let's make a little change: Add a button and the text will change when you click the button.

Expand the Palette panel in such a way that it is a variety of Android controls, locate the Button and drag it to the right virtual phone screen.

Do you feel the button size is inappropriate at this time? The description of android:layout_height= "Wrap_content" in <button/> can be found in the Activity_main.xml file, which indicates that the button size stretches by content.

We changed the Wrap_content to 40DP (DP is a unit of size in Android that ignores display differences from different screen sizes). )

Then change the button width to match_parent (Match_parent has replaced the fill_parent long ago, which represents the same width as its parent container)

The final Activity_main.xml file contains:

<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:app= "Http://schemas.android.com/apk/res-auto"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.test2.MainActivity">    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/hello"Android:textcolor= "@color/colorprimary"android:layout_centerinparent= "true"Android:layout_alignparenttop= "true"Android:id= "@+id/textview" />    <ButtonAndroid:id= "@+id/button"Android:layout_width= "Match_parent"Android:layout_height= "40DP"Android:text= "click me"Android:layout_below= "@id/textview"Android:layout_alignparentstart= "true"Android:layout_margintop= "167DP"Android:onclick= "ClickHandler"/></Relativelayout>

This adds a button click event ClickHandler, so find the App/java/*project*/Mainactivity.java file and edit it as:

 PackageCom.test2;ImportAndroid.os.Bundle;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.view.View;ImportAndroid.widget.TextView; Public classMainactivityextendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_main); }     Public voidClickHandler (View source) {//Gets the text box with ID R.id.textview in the UI interfaceTextView TV =(TextView) Findviewbyid (R.id.textview); //Change the contents of a text boxTv.settext ("Now Time is:" +Newjava.util.Date ()); }}

I just added the method in the public void ClickHandler (View source) {...} section.

Next you can click on the green triangle, such as location, to run the program to see the effect.

Some of the knowledge points: strings in Strings.xml, how they are used in XML files: Key-value pairs in the @string/keycolors.xml, how they are used in XML files: @color/key: A resource used in an XML file: The @< resource corresponds to an internal Class name >/< resource Item name > Java Code Use resource: identifier in r.string.app_name XML file: @+id/< identifier code > The following code means assigning an identifier to a component: @android: Id= "@+id/ok" uses identifiers in XML files: @id/< identifier designator > Using Identifiers in Java code: Findviewbyid () androidmainfest.xml file using Activity is Androi D app manifest file, where android:label= "@string/app_name" specifies Android app tag android:icon= "@mipmap/ic_launcher" specify Android icon

------------End------------

[Android] Development the next day

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.