Android基础
1,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);#任何的項目都需要覆寫父類的onCreate方法
setContentView(R.layout.activity_main);#顯示出你所定義的布局,或指在當(dāng)前活動中加載你所需要的布局
}
2,創(chuàng)造加載布局 res/layout/new/android xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="match_parent"//讓當(dāng)前元素變得和父類一樣寬
? ? android:layout_height="match_parent"
? ? android:orientation="vertical" >布局是垂直的,添加文件只能垂直添加
? ? <Button
? ? ? ? android:id="@+id/button1"//添加一個按鈕
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"//只能包裹住文字
? ? ? ? android:text="Button" />
</LinearLayout>
3,
? ? ? ?@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//隱藏標(biāo)題欄
setContentView(R.layout.first_layout);
}
4,
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//隱藏標(biāo)題欄
setContentView(R.layout.first_layout);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {//創(chuàng)造一個按鈕的監(jiān)聽器,點擊會有響應(yīng),如果出現(xiàn)錯誤,點擊//ctrl+shift+o即可
@Override
public void onClick(View v) {
// TODO 自動生成的方法存根
Toast.makeText(getApplicationContext(), "you clicked button1", Toast.LENGTH_SHORT).show();
}
});
}
轉(zhuǎn)載于:https://blog.51cto.com/13348847/2045017
總結(jié)
- 上一篇: string类assign方法
- 下一篇: 遍历Newtonsoft.Json.Li