Android开发初体验(完美) 第一章 第二次作业80-30-49-43-C7-95(2011)

Android开发初体验(Android Studio4.1.1版本)

一.搭建工程
点击新建项目
选择命名 路径 操作
二.开发初体验
(1).点击MainActivity.java 。注意事项如图及代码 ;如图
点击MainActivity.java
(MainActivity.java 代码)如下图
👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇

package com.example.geoquiz;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private Button mTrueButton; //添加两个按钮成员变量,m开头表示menmber成员变量
private Button mFalseButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTrueButton = (Button) findViewById(R.id.true_button);//引用组件
//为按钮设置监听器,使用匿名内部类
mTrueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//创建提示消息
Toast.makeText(MainActivity.this,R.string.incorrect_toast,Toast.LENGTH_SHORT).show();
}
});

  mFalseButton = (Button) findViewById(R.id.false_button);
  mFalseButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
          Toast.makeText(MainActivity.this,R.string.correct_toast,
                  Toast.LENGTH_SHORT).show();
      }
  });

}
}

👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆

(2).activity_main.xml 如图,
activity_main.xml
更改横纵、间距
(activity_main.xml代码) 如下图,
👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇

<?xml version="1.0" encoding="utf-8"?>

<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:gravity="center"
android:orientation="vertical"
tools:context="com.example.geoquiz.MainActivity">


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="25dp"
    android:text="@string/question_text"

    />
<!--android:padding="24dp"内边距-->
<!--android:text="@string/question_text"对字符串资源的引用-->

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:ignore="ExtraText">

    <Button
        android:id="@+id/true_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/true_button"
        tools:ignore="ButtonStyle"
        android:layout_marginRight="10dp"/>







    <Button
        android:id="@+id/false_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/false_button"
        tools:ignore="ButtonStyle"
        android:layout_marginLeft="10dp"/>

</LinearLayout>

👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆

(3).strings.xml;如图,

(strings.xml 代码)如下图:

👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇

GeoQuiz

Constantinople is the largest city in Turkey.

TRUE
FALSE
Incorrect!
correct

👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆👆

三. 虚拟机上运行
1.如果点击虚拟机没有反应就重新安装虚拟机
点击虚拟机内按键,会出现相应文字


四. 真实机和虚拟机一样,想要手机出现相应的文字,英文和数字等就到Android里面修改虚拟机也是一样。
1
2

这次的教程到这里就结束了,欢迎大家三连。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值