Main5Activity.java 代码如下:
//每点击一次按钮,Button都会+1;
public class Main5Activity extends AppCompatActivity {
private Button button;
private TextView textView;
private Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main5);
button=findViewById(R.id.button);
textView=findViewById(R.id.textView);
button1=findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(Main5Activity.this,"sll",Toast.LENGTH_LONG).show();
textView.setText(String.valueOf(Integer.parseInt((String)textView.getText())+1));
}
});
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =new Intent(Main5Activity.this,Main3Activity.class);
intent.putExtra("data","hello world");
startActivity(intent);
}
});
}
}
activity_main5.xml 代码如下:
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.lnjr.ll2.Main5Activity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#339933"
android:textSize="30sp"
android:text="0"
/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Main3activity.java 代码如下:
public class Main3Activity extends AppCompatActivity {
private EditText editText;
private ImageView imageView;
private TextView textView;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Button button = (Button) findViewById(R.id.button);
editText = (EditText) findViewById(R.id.edit_text);
imageView =(ImageView) findViewById(R.id.image_View);
progressBar=(ProgressBar)findViewById(R.id.progress_bar);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button:
imageView.setImageResource(R.drawable.banbana);
AlertDialog.Builder dialog=new AlertDialog.Builder(Main3Activity.this);
dialog.setTitle(" not allow");
dialog.setMessage("Loading...");
dialog.setCancelable(true);
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
dialog.show();
int progress=progressBar.getProgress();
progress=progress+10;
progressBar.setProgress(progress);
if (progressBar.getVisibility()==View.GONE){
progressBar.setVisibility(View.VISIBLE);
}else {
progressBar.setVisibility(View.GONE);
}
break;
default:
break;
}
}
});
String s=getIntent().getStringExtra("data");
}
}
activity_main3.xml 代码如下:
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.lnjr.ll2.Main3Activity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="琳琳"
android:gravity="center"
android:textSize="24sp"
android:textColor="#00ff00"
/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:textAllCaps="false"
/>
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type something here"
android:maxLines="2"/>
<ImageView
android:id="@+id/image_View"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/aaa"/>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
/>
</LinearLayout>