国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【Android Studio】實現(xiàn)簡易猴子摘桃功能

這篇具有很好參考價值的文章主要介紹了【Android Studio】實現(xiàn)簡易猴子摘桃功能。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

\app\src\main\AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.peach">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Peach">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".PeachActivity"/>
    </application>

</manifest>

\app\src\main\java\com\example\peach\MainActivity.java

package com.example.peach;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private Button pickBtn;
    private TextView peachTotal;
    int count=0;

    private ActivityResultLauncher launcher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
        @Override
        public void onActivityResult(ActivityResult result) {
            if(result != null){
                if(result.getResultCode() == RESULT_OK){
                    Intent data = result.getData();
                    int peachNum = data.getIntExtra("peachNum", 0);
                    Log.i("MainActivity", "onActivityResult: "+ peachNum);
                    count = count + peachNum;
                    peachTotal.setText("桃子" + count + "個");
                }
            }
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pickBtn = findViewById(R.id.pick_btn);
        peachTotal = findViewById(R.id.peach_total);
        pickBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(MainActivity.this, PeachActivity.class);
                launcher.launch(i);
            }
        });
    }
}

\app\src\main\java\com\example\peach\PeachActivity.java

package com.example.peach;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class PeachActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView peach1,peach2,peach3,peach4,peach5,peach6;
    private Button exitBtn;
    private int num = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_peach);
        peach1 = findViewById(R.id.peach1);
        peach2 = findViewById(R.id.peach2);
        peach3 = findViewById(R.id.peach3);
        peach4 = findViewById(R.id.peach4);
        peach5 = findViewById(R.id.peach5);
        peach6 = findViewById(R.id.peach6);
        exitBtn = findViewById(R.id.exit_btn);
        peach1.setOnClickListener(this);
        peach2.setOnClickListener(this);
        peach3.setOnClickListener(this);
        peach4.setOnClickListener(this);
        peach5.setOnClickListener(this);
        peach6.setOnClickListener(this);
        exitBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if(view.getId() == R.id.peach1){
            info(peach1);
        }else if(view.getId() == R.id.peach2){
            info(peach2);
        }else if(view.getId() == R.id.peach3){
            info(peach3);
        }else if(view.getId() == R.id.peach4){
            info(peach4);
        }else if(view.getId() == R.id.peach5){
            info(peach5);
        }else if(view.getId() == R.id.peach6){
            info(peach6);
        }else if(view.getId() == R.id.exit_btn){
            returnData();
        }
    }

    private void returnData() {
        Intent i = new Intent();
        i.putExtra("peachNum", num);
        setResult(RESULT_OK,i);
        finish();
    }

    private void info(ImageView imageView) {
        imageView.setVisibility(View.INVISIBLE);
        num++;
    }

    @Override
    public void onBackPressed() {
        Intent i = new Intent();
        i.putExtra("peachNum", num);
        setResult(RESULT_OK,i);
        finish();
    }
}

\app\src\main\res\values\themes.xml

<resources xmlns:tools="http://schemas.android.com/tools">
    <!-- Base application theme. -->
    <style name="Theme.Peach" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
        <!-- Primary brand color. -->
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
        <item name="colorOnPrimary">@color/white</item>
        <!-- Secondary brand color. -->
        <item name="colorSecondary">@color/teal_200</item>
        <item name="colorSecondaryVariant">@color/teal_700</item>
        <item name="colorOnSecondary">@color/black</item>
        <!-- Status bar color. -->
        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
        <!-- Customize your theme here. -->
    </style>
</resources>

\app\src\main\res\layout\activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/bg">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/teal_700"
        android:gravity="center"
        android:padding="5dp"
        android:text="首頁"
        android:textColor="#fff"
        android:textSize="25sp" />

    <ImageView
        android:id="@+id/monkey"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/monkey"
        android:layout_centerVertical="true"/>

    <Button
        android:id="@+id/pick_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/monkey"
        android:layout_toEndOf="@+id/monkey"
        android:background="@drawable/btn_peach"
        android:text="去桃園"
        android:textSize="22sp" />

    <ImageView
        android:id="@+id/peach"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/pick_btn"
        android:layout_alignLeft="@+id/pick_btn"
        android:layout_marginTop="50dp"
        android:src="@drawable/peach_pic" />

    <TextView
        android:id="@+id/peach_total"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/peach"
        android:layout_toEndOf="@+id/peach"
        android:text="摘到0個"
        android:textSize="22sp" />

</RelativeLayout>

\app\src\main\res\layout\activity_peach.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".PeachActivity"
    android:background="@drawable/tree_bg">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/teal_700"
        android:gravity="center"
        android:padding="5dp"
        android:text="桃園"
        android:textColor="#fff"
        android:textSize="25sp" />

    <ImageView
        android:id="@+id/tree"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/tree" />

    <ImageView
        android:id="@+id/peach1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/tree"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:src="@drawable/peach_pic" />

    <ImageView
        android:id="@+id/peach2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/peach1"
        android:layout_alignLeft="@+id/tree"
        android:layout_marginLeft="50dp"
        android:src="@drawable/peach_pic" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/peach_pic"
        android:id="@+id/peach3"
        android:layout_below="@+id/peach1"
        android:layout_alignRight="@+id/tree"
        android:layout_marginRight="50dp"/>

    <ImageView
        android:id="@+id/peach4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/peach2"
        android:layout_centerHorizontal="true"
        android:src="@drawable/peach_pic" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/peach_pic"
        android:id="@+id/peach5"
        android:layout_below="@+id/peach2"
        android:layout_toStartOf="@+id/peach4"
        android:layout_marginRight="25dp"/>

    <ImageView
        android:id="@+id/peach6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/peach2"
        android:layout_toEndOf="@+id/peach4"
        android:src="@drawable/peach_pic"
        android:layout_marginLeft="20dp"/>

    <Button
        android:id="@+id/exit_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="50dp"
        android:background="@drawable/btn_peach"
        android:text="退出桃園"
        android:textSize="22sp" />

</RelativeLayout>

?android小猴子摘桃,Java,HTML,android,android studio,ide

android小猴子摘桃,Java,HTML,android,android studio,ide?

?文章來源地址http://www.zghlxwxcb.cn/news/detail-742546.html

到了這里,關(guān)于【Android Studio】實現(xiàn)簡易猴子摘桃功能的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關(guān)文章

  • t2017遞推2猴子摘桃

    2、猴子摘桃(nhoi2005xx1) Description 果園里種了很多桃樹,當桃樹開始結(jié)果的時候,猴子便會成群結(jié)隊地前來摘桃。? 猴子們第一天會摘掉桃子的一半還多一個,第二天再摘第一天剩下的一半還多一個,以后每天均摘掉上一天剩下的一半還多一個,到第N天時,樹上就只剩下兩個

    2024年02月06日
    瀏覽(18)
  • Android Studio實現(xiàn)簡易計算器(帶橫豎屏,深色淺色模式,更該按鈕顏色,selector,style的使用)

    Android Studio實現(xiàn)簡易計算器(帶橫豎屏,深色淺色模式,更該按鈕顏色,selector,style的使用)

    目錄 前言 運行結(jié)果: 運行截屏(p50e) ?apk文件 源碼文件 ?項目結(jié)構(gòu) 總覽 MainActivity.java drawable 更改圖標的方法: blackbutton.xml bluebuttons.xml greybutton.xml orangebuttons.xml whitebutton.xml layout 布局文件 ?豎屏: 橫屏: values ? ? ? ? colors.xml strings.xml styles 淺色模式 深色模式 themes.xml

    2024年02月06日
    瀏覽(29)
  • Android Studio實現(xiàn)多功能日記本

    Android Studio實現(xiàn)多功能日記本

    本次實現(xiàn)了功能實用且齊全的日記本,界面友好,使用便捷,采用MVC架構(gòu)設計。使用SQLite數(shù)據(jù)庫存儲數(shù)據(jù),數(shù)據(jù)表有主題表、主題序號表、日記表、日記條目表、備忘錄表、備忘錄條目表和聯(lián)系人表。系統(tǒng)有10多個頁面,主要功能包含:添加、修改、刪除和查詢主題,主題包

    2024年02月02日
    瀏覽(35)
  • Android Studio簡易計算器

    Android Studio簡易計算器

    目錄 第一步,創(chuàng)建新項目 第二步,設計UI 第三步,實現(xiàn)計算邏輯 第四步,測試應用程序 隨著移動互聯(lián)網(wǎng)的普及,手機應用程序已經(jīng)成為人們生活中不可或缺的一部分。計算器是一類被廣泛使用的應用程序之一,因此學習如何開發(fā)一款簡易的計算器應用程序是學習Android Stu

    2024年02月08日
    瀏覽(21)
  • android studio簡易app實例

    以下是一個使用Android Studio創(chuàng)建的簡易App實例。這個App包括一個主頁面,一個關(guān)于頁面和一個設置頁面。 步驟1:創(chuàng)建新的Android項目 打開Android Studio,點擊\\\"File\\\" - \\\"New\\\" - \\\"New Project\\\"。在新的對話框中,選擇\\\"Empty Activity\\\",然后點擊\\\"Next\\\"。 在接下來的頁面中,填寫你的應用名稱,應

    2024年04月14日
    瀏覽(22)
  • 【Android Studio】簡易計算器

    【Android Studio】簡易計算器

    簡易計算器要求: 1,操作簡單,易于掌握,界面簡單。 2.方便進行加,減,乘,除等操作。數(shù)字保留小數(shù)點后兩位。 3.包含小數(shù)點運算和輸入回退功能。 4.能夠進行多次疊加運算。 5.系統(tǒng)能夠進行多次疊加運算。 6.系統(tǒng)可以穩(wěn)定運行。 功能圖如下: 邏輯流程圖如下: 項目建

    2024年02月08日
    瀏覽(21)
  • Android Studio|使用SqLite實現(xiàn)一個簡單的登錄注冊功能

    Android Studio|使用SqLite實現(xiàn)一個簡單的登錄注冊功能

    本學期學習了Android Studio這門課程,本次使用Android Studio自帶的sqlite數(shù)據(jù)庫實現(xiàn)一個簡單的登錄注冊功能。 目錄 一、了解什么是Android Studio? 二、了解什么是sqlite? 三、創(chuàng)建項目文件 ?四、創(chuàng)建活動文件和布局文件。 五、創(chuàng)建數(shù)據(jù)庫,連接數(shù)據(jù)庫 ?六、創(chuàng)建實體類,實現(xiàn)注

    2024年02月06日
    瀏覽(51)
  • Android如何實現(xiàn)地圖定位?Android studio+百度地圖API+Android6.0系統(tǒng)實現(xiàn)地圖顯示、地址設置、點擊地圖定位功能(詳細)

    Android如何實現(xiàn)地圖定位?Android studio+百度地圖API+Android6.0系統(tǒng)實現(xiàn)地圖顯示、地址設置、點擊地圖定位功能(詳細)

    文章說明: 本文初衷是為了記錄畢設學習過程,避免忘記操作流程。該功能是畢業(yè)設計的Android軟件端的功能之一,本文將從獲取百度地圖密鑰(AK)開始,詳細地對地圖定位配置和相關(guān)代碼進行說明, 文末將附上實現(xiàn)該功能的代碼。后續(xù)等答辯完成會把整個Android端代碼上傳

    2024年02月03日
    瀏覽(22)
  • Android Studio:Intent與組件通信實現(xiàn)頁面跳轉(zhuǎn)功能

    Android Studio:Intent與組件通信實現(xiàn)頁面跳轉(zhuǎn)功能

    ??Android Studio 專欄正在持續(xù)更新中,案例的原理圖解析、各種模塊分析??這里都有哦,同時也歡迎大家訂閱專欄,獲取更多詳細信息哦??? ?個人主頁:零小唬的博客主頁 ??歡迎大家 ??點贊 ??評論 ??收藏 ?作者簡介:20級計算機專業(yè)學生一枚,來自寧夏,可能會去

    2024年02月05日
    瀏覽(25)
  • 初學編程 第一個小程序Android studio實現(xiàn)計算器功能

    源代碼下載:https://gitee.com/zha-yingying/calculator.git 1.建立一個新的Layout,我這里使用的是GridLayout(網(wǎng)格布局),提取屏幕寬度(方便后面設置子控件的寬度)GridLayout的特點是自定義網(wǎng)格布局有幾行幾列,我們可以將自控件自定義放在第幾行第幾列。 2.建立一個新的textview(文本

    2023年04月14日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包