android初体验

今天看了一会安卓的书,对安卓有了一些粗浅的了解。

首先xml文件是对界面进行布局的所以在做一个apk之前需要对apk文件进行编辑。

第二string.xml这个文件是对字符资源进行存储的。

附上关键代码:

 

<TextView
android:id="@+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/question"
android:textSize="30dp"
android:gravity="center_horizontal" />

<Button
android:id="@+id/truebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_gravity="center_horizontal"
android:text="@string/true_button" />

<Button
android:id="@+id/falsebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_gravity="center_horizontal"
android:text="@string/false_button" />

<string name="app_name">My Application</string>
<string name="true_button">喜欢</string>
<string name="false_button">不喜欢</string>
<string name="question">你喜欢我吗?</string>

true_button=(Button) findViewById(R.id.truebutton);
true_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast toast=Toast.makeText(getApplicationContext(),"你特么瞎啊!!",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER,0,0);
toast.show();
}
});
//true
false_button=(Button) findViewById(R.id.falsebutton);
false_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast toast=Toast.makeText(getApplicationContext(),"你真有眼光!!",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER,0,0);
toast.show();
}
});

 附上demo下载地址:https://files.cnblogs.com/files/fyz666/pro1.apk

 

 

posted @ 2017-03-10 16:39  爱编程的文科生  阅读(153)  评论(0编辑  收藏  举报