close
workspace的路徑: C:\Users\ryan\workspace\
專案名稱:MyFirstAndroidProject
開啟MainActivity.java加入三個import
1: import android.widget.Button;
2: import android.widget.TextView;
3: import android.widget.LinearLayout;
加入一個Layout物件, 在layout物件上加入一個text和button
1: public class MainActivity extends Activity {
2:
3: @Override
4: protected void onCreate(Bundle savedInstanceState) {
5: super.onCreate(savedInstanceState);
6: /***********************************/
7: LinearLayout layout = new LinearLayout(this);
8: layout.setOrientation(LinearLayout.VERTICAL);
9: TextView text = new TextView(this);
10: text.setText(super.getString(R.string.Text_Str));
11: //text.setText(super))
12: Button but = new Button(this);
13: but.setText(super.getString(R.string.Btn_Str));
14: layout.addView(text);
15: layout.addView(but);
16: super.setContentView(layout);
17: /***********************************/
18: //setContentView(R.layout.activity_main);
19: }
res->values->strings.xml
定義字串Btn_Str和Text_Str
範例程式: MyFirstAndroidProject
全站熱搜
留言列表