Android Learning _7 / 22

A, Android project directory structure

1.          AndroidManifest.xml : the entire Android configuration items, registration of the components

<activity android:name=".MainActivity" >
    <intent-filter>
        <action
android:name="android.intent.action.MAIN" />          //主活动

        <category
android:name="android.intent.category.LAUNCHER" />     //首先启动的活动
    </intent-filter>
</activity>

2.         Activity

Separating the view logic

. 1)          AppCompatActivity : backward compatible with the Activity , the Activity subclass.

2)          oneCreate () method: create an event will execute.

3.          build.gradle file

1)          Gradle is a project build tools

2)          a project has two build.gradle

a)          under the outermost catalog: Global project build configuration, generally without modification

b)          App directory

defaultConfig闭包:

applicationId : In this modification package name

                             dependencies闭包:

                                    Dependencies project: local, library, remote

Second, resources

Reference resources :

Code by R.string.app_name

XML via @ string / app_name

 

Third, use the logging facility

1.         log.v ()       log.d()       log.i()        log.w()      log.e()

Level: Low → High

2.   Log.d("MainActivity","oneCreate execute");

Tag : Filter print information ( usually the name of the current class, logt can be generated automatically TAG constant )

msg : the specific content of print

3.          logcat : filter, log level control, keyword filtering

 

Fourth, the basic usage activity

1.          Create Event

2.          Create and load distribution

A)          XML Definition Id : Atto Tasu Id / Button_1

b)          loading layout: the setContentView (R.layout.first_layout); 

3.          In AndroidManifest registration

By <Activity> , in <application> lower ( automatic registration )

a)          a statement of the main activities:

b)          plus the title bar

<activity android:name=".FirstActivity"
   
android:label="This is FirstActivity">       

4.          activity using Toast

// findViewById () Gets the layout elements defined, then View down converted to the Button
       
the Button Button1 = (the Button) the findViewById (R.id. Button_1 ) ;
       
/ *
        * the Button
is setOnClickListener () Method : register a listener
        * Toast .makeText ()
method : create Toast Object
        *
there seems to use anonymous inner classes? Java foundation not quite sure. . .
       * * /
// button1.setOnClickListener (new new View.OnClickListener () {
           
@Override
           
public void the onClick (View V) {
                Toast. MakeText (FirstActivity.
The this,"You click Button 1",
                       
Toast.LENGTH_SHORT).show();
           
}
        })
;

step1 : the definition of trigger points - Button ( use findViewById () Gets )

stpe2 : listener registered for the button, the listener has OnClick () method, click the button on the implementation OnClick ()

stpe3 : the OnClick () call Toast.makeText () to create Toast objects, this method has three parameters: Context , text display, the display duration


Guess you like

Origin www.cnblogs.com/pomodoro/p/11229646.html