From d7ca9ac5e5b64e3317808f1f3fec769e0b6ef1c3 Mon Sep 17 00:00:00 2001 From: xy0dls <2153766822@qq.com> Date: Wed, 23 Apr 2025 23:22:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99onCreate()=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/micode/notes/ui/NoteEditActivity.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java index 862883b..fe746ae 100644 --- a/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java +++ b/MiNote/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java @@ -47,6 +47,7 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -74,6 +75,7 @@ import java.util.regex.Pattern; public class NoteEditActivity extends Activity implements OnClickListener, NoteSettingChangedListener, OnTextViewChangeListener { + private static final int PHOTO_REQUEST = 1; private class HeadViewHolder { public TextView tvModified; @@ -159,8 +161,26 @@ public class NoteEditActivity extends Activity implements OnClickListener, return; } initResources(); + + //根据id获取添加图片按钮 + final ImageButton add_img_btn = (ImageButton) findViewById(R.id.add_img_btn); + //为点击图片按钮设置监听器 + add_img_btn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Log.d(TAG, "onClick: click add image button"); + //ACTION_GET_CONTENT: 允许用户选择特殊种类的数据,并返回(特殊种类的数据:照一张相片或录一段音) + Intent loadImage = new Intent(Intent.ACTION_GET_CONTENT); + //Category属性用于指定当前动作(Action)被执行的环境. + //CATEGORY_OPENABLE; 用来指示一个ACTION_GET_CONTENT的intent + loadImage.addCategory(Intent.CATEGORY_OPENABLE); + loadImage.setType("image/*"); + startActivityForResult(loadImage, PHOTO_REQUEST); + } + }); } + /** * Current activity may be killed when the memory is low. Once it is killed, for another time * user load this activity, we should restore the former state