Android开发学习(6)---GeoQuiz(5)


前言

本章,我们为GeoQuiz应用添加第二个activity。一个activity控制一屏信息,新activity将带来 第二个用户界面,方便用户偷看当前问题的答案。

一.添加字符串资源(strings.xml)

<resources>      
...     
<string name=" Incorrect_toast"> Incorrect!</string>     
<string name="warning_text">Are you sure you want to do this?</string>     
<string name="show_answer_button">Show Answer</string>     
<string name="cheat_button">Cheat!</string>     
<string name="judgment_toast">Cheating is wrong.</string> 
</resources> 

二.创建新的 activity

在随后弹出的对话框中,Activity Name处输入CheatActivity,如图5-4所示。这是Activity 子类的名字。Layout Name自动赋值为activity_cheat。这是向导为布局文件创建的基本名称.

三。第二个activity的布局组件定义(activity_cheat.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  
android:layout_width="match_parent"   
android:layout_height="match_parent"  
android:orientation="vertical"  
android:gravity="center"  tools:context="com.bignerdranch.android.geoquiz.CheatActivity"> 
    <TextView   
    android:layout_width="wrap_content"   
    android:layout_height="wrap_content"   
    android:padding="24dp"   
    android:text="@string/warning_text"/> 
    <TextView   android:id="@+id/answer_text_view"   
    android:layout_width="wrap_content"   
    android:layout_height="wrap_content"   
    android:padding="24dp"   
    tools:text="Answer"/> 
    <Button   
    android:id="@+id/show_answer_button"  
     android:layout_width="wrap_content"   
     android:layout_height="wrap_content"   
     android:text="@string/show_answer_button"/> 
</LinearLayout> 

四.在manifest配置文件中声明 activity

(AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"     
package="com.bignerdranch.android.geoquiz" 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值