原创:http://blog.chinaunix.net/uid/23795897.html
一、android编程,框架:建立一个工程后,有:
Application Name: kylin_app1. //生产后的apk名和左上角名字都是这个。
Project Name : kylin_project1
Package Name : kylin.package1
Activity Name : kylin_activity 首写大写。
Layout Name: kylin_layout
1、src -》MainActivity.java:这个是主要编程的地方,相当于main函数。
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); TextView myTextView =(TextView) findViewById(R.id.myTextView); //可以通过R.java中的id找 Button myButton=(Button)findViewById(R.id.myButtonView); myTextView.setText("我家的丫头"); myButton.setText("我的");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
2、gen =》R.java
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class id {
public static final int menu_settings=0x7f070002; public static final int myButtonView=0x7f070001; //这些都是自动生成的,不能改。 public static final int myTextView=0x7f070000;
}
public static final class layout {
public static final int activity_main=0x7f030000;
}
public static final class menu {
public static final int activity_main=0x7f060000;
}
public static final class string {
public static final int app_name=0x7f040000;
public static final int hello_world=0x7f040002;
public static final int menu_settings=0x7f040001;
}