【发布时间】:2021-03-31 23:14:20
【问题描述】:
2021-04-01 00:33:47.674 19798-19798/? E/Zygote: isWhitelistProcess - Process is Whitelisted
2021-04-01 00:33:47.676 19798-19798/? E/Zygote: accessInfo : 1
2021-04-01 00:33:47.733 19798-19798/? E/programingbasi: Unknown bits set in runtime_flags: 0x8000
这些在 logcat-error 上(我不确定它是否对您回答有帮助)
由于我只编辑了下面的java代码和xml代码,所以我只添加了这些代码
Java 代码 '''
package com.song.androidprogramingbasic;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
MediaPlayer mp = MediaPlayer.create(this, R.raw.alarm_sound);
@Override
protected void onCreate(Bundle savedInstanceState){ /* 가장 먼저 실행되는 함수*/
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView title = (TextView) findViewById(R.id.first_screen);
title.setText(R.string.Hello_INU);
}
public void Button1(View view){
Intent intent = new Intent(MainActivity.this, Button1Activity.class);
startActivity(intent); /*Intent객체를 받아서, intent객체의 정보로 뭔가를 한다고 함*/
}
public void Button2(View view){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:010-1234-5678"));
startActivity(intent); /*Intent객체를 받아서, intent객체의 정보로 뭔가를 한다고 함*/
}
public void alert_Dialog(View view){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.button4_text);
builder.setTitle(R.string.button4_title);
builder.setPositiveButton(R.string.button4_dismiss, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert_dialog = builder.create();
alert_dialog.show();
}
public void alarm_sound(View view){
mp.seekTo(0);
mp.start();
}
public void on_Long_Click(View view){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.button8_text);
builder.setTitle(R.string.button8_title);
builder.setPositiveButton(R.string.button8_dismiss, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alert_dialog = builder.create();
alert_dialog.show();
}
}
'''
mxl 代码
<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"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="@+id/first_screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="@string/first_screen"
/>
<EditText
android:id="@+id/first_screen_EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autofillHints="@string/first_screen_edittext"
android:hint="@string/first_screen_edittext"
android:singleLine="false"
android:inputType="text"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="Button1"
android:text="@string/button1" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="Button2"
android:text="@string/button2" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button3" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button4"
android:onClick="alert_Dialog"/>
<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button5" />
<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/button6" />
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="alarm_sound"
android:text="@string/button7" />
<Button
android:id="@+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="on_Long_Click"
android:longClickable="true"
android:focusable="true"
android:text="@string/button8" />
<ImageView
android:id="@+id/first_screen_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="50dp"
android:src="@mipmap/incheon_national_university"
android:adjustViewBounds="true"
android:layout_marginStart="50dp"
android:contentDescription="@mipmap/incheon_national_university" />
</LinearLayout>
</LinearLayout>
【问题讨论】:
标签: java android xml android-studio