imageview
<ImageView
android:id="@+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img"
/>
出现了一些小问题,通过https://blog.csdn.net/qq_32226379/article/details/52574000解决了
progressbar
点击一下按钮让进度条出现,点击一下按钮让进度条消失 mainactivity代码
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private EditText editText;
private ImageView imageView;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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(this);
}
@Override
public void onClick(View v){
switch (v.getId()){
case R.id.button:
if(progressBar.getVisibility()==View.GONE){//如果可见隐藏掉如果不可见就可见
progressBar.setVisibility(View.VISIBLE);
}else{
progressBar.setVisibility(View.GONE);
}
break;
default:
break;
}
}
}
activity_main.xml代码
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
进度条
activity_main.xml代码
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"/>
mainactivity代码
public void onClick(View v){
switch (v.getId()){
case R.id.button:
int progress = progressBar.getProgress();
progress = progress +10;
progressBar.setProgress(progress);
break;
default:
break;
}
}
}
AlertDialog对话框
mainactivity源码
@Override public void onClick(View v){ switch (v.getId()){ case R.id.button: AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);//创建一个实例 dialog.setTitle("This is Dialog");//标题 dialog.setMessage("Something important.");//内容 dialog.setPositiveButton("OK",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog,int which){} }); dialog.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog,int which){} }); dialog.show(); break; default: break; } }
progressdialog
@Override public void onClick(View v){ switch (v.getId()){ case R.id.button: ProgressDialog progressDialog = new ProgressDialog (MainActivity.this); progressDialog.setTitle("This is ProgressDialog"); progressDialog.setMessage("Loading......"); progressDialog.setCancelable(true); progressDialog.show(); break; default: break; } } }