Android Getting Started Notes

#Android project directory structure (familiar)
* Activity: the interface displayed when the application is opened
* src: project code
* R.java: resource id of all resource files in the project
* Android.jar: Android jar package, import this package To use Android's api
* libs: import third-party jar packages
* assets: store resource files, such as mp3, video files
* bin: store compiled and packaged files
* res: store resource files, stored in this folder All resource files will generate resource ids
* drawable: store image resources
* layout: store layout files, assign the layout file to the activity through the resource id, and the interface will display the layout defined by the layout file
* menu: define the style of the menu
* Strings .xml: store string resources, each resource will have a resource id


###Android configuration file (manifest file) (familiar)
* Specify the package name of the application


package="com.itheima.helloworld"
* data/data/com.itheima.helloworld (package name specified by the code above)
* The files generated by the application will be stored in this path


* All four components of Android need to be configured in the manifest file before use
* The configuration of <Application/> is valid for the entire application
* The configuration of <activity/> is valid for the


activity- --
#DDMS (master)
* Dalvik debug monitor service
* Dalvik debug monitor service


--- #Commonly
used adb commands (master)
###Android debug bridge: Android debug bridge
* adb start-server: start adb process
* adb kill -server: kill the adb process
* adb devices: view the devices currently connected to the development environment, this command can also start the adb process
* adb install XXX.apk: install apk to the simulator
* adb uninstall package name: delete the Apply
*adb shell: enter linux command line
* ps: View running process
* ls: View the file structure in the current directory
* netstat -ano: View the processes occupying the port


--------------- #Phone
dialer (master)
>Function: The user enters a number, Click the dial button to start the system calling application to dial the number
###1. Define the layout
1. The component must set the width and height, otherwise it cannot be compiled


android:layout_width="wrap_content"
        android:layout_height="wrap_content"
2. If you want to operate a component in java code, the component needs to set id, so that you can get this component through id in the code


android:id="@+id/et_phone"
###2. Set click listener


for button 1. Set button to listen


//Get the button object
        Button by id bt_call = (Button) findViewById(R.id.bt_call);
        //Set the button to click
        bt_call.setOnClickListener(new MyListener());


###3. Get the number entered by the user


//Get the number entered by the user, first get the input box component
EditText et_phone = (EditText) findViewById(R.id.et_phone);
String phone = et_phone.getText().toString();


###4. Dial out the number
1. The Android system is based on the action mechanism to call the application of the system, you tell the system what action you want, the system will The application that can do this action will be given to you. If there is no such application, an exception will be thrown
. 2. Set the action and inform the system through the intention


// dial out the number
// first create an intent object
Intent intent = new Intent();
//set the action, call
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phone));
// Tell the system about the intent
startActivity(intent);


3. Add permission


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


---------- #Four ways to
write click events (master)
###First type
* Define a MyListener to implement the onClickListener interface


Button bt1 = (Button) findViewById(R.id.bt1);
        bt1.setOnClickListener(new MyListener());


###Second
* Define an anonymous inner class to implement the onClickListener interface


Button bt2 = (Button) findViewById(R.id.bt2);
        bt2.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
System.out.println("Second");

}
});


###Third
* Let the current activity implement the onClickListener interface


Button bt3 = (Button) findViewById(R.id.bt3);
        bt3.setOnClickListener(this);


###Fourth
* Set the onClick property for the Button node,


android:onClick="click"
 
* Then define a method with the same name as the attribute value in the activity


public void click(View v){
System.out.println("Fourth");
}


--------
#SMS Sender (Master)
> Function: The user enters the number and content of the SMS, clicks the send button, and calls the SMS api to send the SMS to the specified number
###1. Define the layout
* of the input box hint


android:hint="Please enter the number"  
###2. Complete the click event
* First set the onClick attribute to the Button component

onClick="send"
*Define this method in Activity

public void send(View v){}
###3. Get the number and content entered by the user


EditText et_phone = (EditText) findViewById(R.id.et_phone);
    EditText et_content = (EditText) findViewById(R.id.et_content);
    String phone = et_phone.getText().toString();
    String content = et_content.getText().toString();
###4. Call the api for sending SMS


//Call the api for sending SMS
    SmsManager sm = SmsManager.getDefault();
   
    //send messages
    sm.sendTextMessage(phone, null, content, null, null);
* Add permission


<uses-permission android:name="android.permission.SEND_SMS"/>
* If the SMS is too long, it needs to be split


List<String> smss = sm.divideMessage(content);


--- #Common
layout
###Linear layout
* LinearLayout
* Specify the arrangement direction of each node


android:orientation="horizontal"
* set right alignment


android:layout_gravity="right"
* In vertical layout, only left and right alignment and horizontal centering, top bottom alignment and vertical centering are invalid
* When horizontal layout, only top bottom alignment and vertical centering
are available* Be careful not to use match_parent Push other components out
* A very important property of linear layout: weight


android:layout_weight="1"
* Weight: proportionally distribute the remaining width or height of the screen

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325768858&siteId=291194637