Android
1111吧
全部回复
仅看楼主
level 5
㦝廲 楼主
2025年11月14日 03点11分 1
level 5
㦝廲 楼主
package com.example.firstapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class MainActivity extends AppCompatActivity {
private Button btnWriteDisk,btnReadDisk,btnWriteSD,btnReadSD,btnWriteSp,btnReadSP,btnJSON;
private TextView txtDisplay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnWriteDisk=(Button)findViewById(R.id.button);
btnReadDisk=(Button)findViewById(R.id.button2);
btnWriteSD=(Button)findViewById(R.id.button3);
btnReadSD=(Button)findViewById(R.id.button4);
btnWriteSp=(Button)findViewById(R.id.button5);
btnReadSP=(Button)findViewById(R.id.button6);
btnJSON=(Button)findViewById(R.id.button7);
txtDisplay=(TextView)findViewById(R.id.textView);
btnWriteDisk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str=" 出塞\r\n\r\n 唐·王昌龄\r\n\r\n秦时明月汉时关,\r\n\r\n万里长征人未还。\r\n\r\n但使龙城飞将在,\r\n\r\n不教胡马度阴山。";
try{
FileOutputStream fos=openFileOutput("poeml.txt",MODE_PRIVATE);
fos.write(str.getBytes());
fos.close();
Toast.makeText(MainActivity.this,"硬盘存储文件成功!",Toast.LENGTH_LONG).show();
}catch (Exception el) {
Toast.makeText(MainActivity.this, "硬盘存储文件出现问题!",Toast.LENGTH_LONG).show();
}
}
});
btnReadDisk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str="";
try{
FileInputStream fis=openFileInput("poeml.txt");
byte[] buffer=new byte[fis.available()];
fis.read(buffer);
str=new String(buffer);
fis.close();
txtDisplay.setText(str);
}catch (Exception e2) {
Toast.makeText(MainActivity.this, "读取硬盘文件出现问题!", Toast.LENGTH_LONG).show();
}
}
});
btnWriteSD.setOnClickListener(new View.OnClickListener() {
@Override
public void on
2025年11月14日 03点11分 2
level 5
㦝廲 楼主
package com.example.firstapplication;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
private EditText edtUrl;
private Button btnWeb;
private ImageView img;
protected static final int HTTPOK=1;
protected static final int HTTPERROR=0;
private Handler handler=new Handler(){
public void handleMessage(android.os.Message msg){
if(msg.what==HTTPOK){
Bitmap bmp1=(Bitmap)msg.obj;
img.setImageBitmap(bmp1);
}
else if(msg.what==HTTPERROR){
Toast.makeText(MainActivity.this,"网络访问失败",Toast.LENGTH_LONG).show();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtUrl=(EditText)findViewById(R.id.editText);
btnWeb=(Button) findViewById(R.id.button);
img=(ImageView)findViewById(R.id.imageView);
ActivityCompat.requestPermissions(this,new String[]{"android.permission.INTERNET"},1);
btnWeb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String strPath=edtUrl.getText().toString();
if (strPath.isEmpty()){
Toast.makeText(MainActivity.this,"图片网址不能空",Toast.LENGTH_LONG).show();
}
else {
new Thread(){
private HttpURLConnection con;
private Bitmap bmp2;
public void run(){
try {
URL url=new URL(strPath);
con=(HttpURLConnection)url.openConnection();
con.setRequestMethod("GET");
con.setConnectTimeout(5000);
int code=con.getResponseCode();
if (code==200){
InputStream is=con.getInputStream();
bmp2= BitmapFactory.decodeStream(is);
Message msg=new Message();
msg.what=HTTPOK;
msg.obj=bmp2;
handler.sendMessage(msg);
}
else {
Message msg=new Message();
msg.what=HTTPERROR;
handler.sendMessage(msg);
}
con.disconnect();
}catch (Exception e){
Message msg=new Message();
msg.what=HTTPERROR;
handler.sendMessage(msg);
}
}
}.start();
}
}
});
}
}
2025年12月01日 03点12分 4
level 5
㦝廲 楼主
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.firstapplication">
<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.AppCompat.DayNight.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
2025年12月01日 03点12分 5
level 5
㦝廲 楼主
<?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">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srcCompat="@mipmap/ic_launcher"
android:layout_marginTop="60dp"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="抓取"
android:layout_marginLeft="215dp"/>
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="请输入图片网址"
android:inputType="textPersonName" />
2025年12月01日 03点12分 6
level 1
package com.example.firstapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ImageView img;
private Button btnAlpha,btnRotate,btnScale,btnTranslate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img=(ImageView)findViewById(R.id.imageView);
btnAlpha=(Button) findViewById(R.id.button);
btnRotate=(Button)findViewById(R.id.button2);
btnScale=(Button)findViewById(R.id.button3);
btnTranslate=(Button)findViewById(R.id.button4);
btnAlpha.setOnClickListener(this);
btnRotate.setOnClickListener(this);
btnScale.setOnClickListener(this);
btnTranslate.setOnClickListener(this);
Bitmap bmp=Bitmap.createBitmap(800,1200,Bitmap.Config.ARGB_8888);
Paint p=new Paint();
p.setColor(Color.RED);
p.setFakeBoldText(true);
p.setShadowLayer(8,5,5,Color.BLACK);
p.setTextSize(260);
Canvas can=new Canvas(bmp);
can.drawText("周星星",20,900,p);
img.setImageBitmap(bmp);
}
public void onClick(View v) {
switch (v.getId ()) {
case R.id.button:
Animation alpha = AnimationUtils.loadAnimation(this,R.anim.alpha_animation);
img.startAnimation(alpha);
break;
case R.id.button2:
Animation rotate = AnimationUtils.loadAnimation(this,R.anim.rotate_animation);
img.startAnimation(rotate);
break;
case R.id.button3:
Animation scale = AnimationUtils.loadAnimation(this,R.anim.scale_animation);
img.startAnimation(scale);
break;
case R.id.button4:
Animation translate = AnimationUtils.loadAnimation(this,R.anim.translate_animation);
img.startAnimation(translate);
break;
}
}
}
2025年12月03日 02点12分 9
1