初学Android,第一个项目:GeoQuiz。
1. 项目演示:
a. 让用户对地理问题作出True/False的回答,并给出提示。
b. 用户不会时,可以作弊
c. 点击作弊后弹出警告
d. 如果用户真的看了答案,给出提示
2. 步骤:
a. 新建一个Android工程(这里用Android Studio实现)
b. 编写界面
一共两个界面:
(0) string.xml (项目中所用到的字符串)
这里将项目中所有要显示的字符串都放在这里,便于以后修改(真实的情况是直接写死在界面的xml里面会有warning,强迫症受不了~)
<resources>
<string name="app_name">GeoQuiz</string>
<string name="true_button">True</string>
<string name="false_button">False</string>
<string name="correct_toast">Correct!</string>
<string name="incorrect_toast">Incorrect!</string>
<string name="next_button">Next</string>
<string name="prev_button">Prev</string>
<string name="question_oceans">The Pacific Ocean is larger than the Atlantic Ocean.</string>
<string name="question_mideast">The Suez Canal connects the Red Sea and the Indian Ocean.</string>
<string name="question_africa">The source of the Nile River is in Egypt.</string>
<string name="question_americas">The Amazon River is the longest river in the Americans.</string>
<string name="question_asia">Lake Baikal is the world\'s oldest and deepest freshwater lake.</string>
<string name="cheat_button">Cheat!</string>
<string name="warning_text">Are you sure you want to do this?</string>
<string name="show_answer_button">Show Answer</string>
<string name="judgment_toast">Cheating is wrong.</string>
<string name="tell_you_the_answer">Current question:\n %1$s \n Answer:\n %2$s</string>
</resources>
(1) activity_quiz.xml (第一个界面)
这里笔者喜欢Android Studio最近默认的constraintLayout,直接对着design视图拖控件就可以了。
对于constraintLayout的详细用法请看这里
xml:喜欢对constraintLayout手写xml的请看这篇文章,下面还是把xml文件贴出来:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tool