CÓDIGO PARA HACER UNA PANTALLA QUE APAREZCA UNOS SEGUNDOS

package com.example.splash_screen;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
public class SplashScreen extends Activity {
private boolean backbtnPress;
private static final int SPLASH_DURATION = 3000; // 3 segundos
private Handler myHandler;
@Override
protected void onCreate(Bundle savedInstanceState){
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate (savedInstanceState);
setContentView(R.layout.activity_splash_screen);
myHandler = new Handler();
myHandler.postDelayed(new Runnable() {
@Override
public void run() {
finish();
if(!backbtnPress)
{
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
SplashScreen.this.startActivity(intent);
}
}
}, SPLASH_DURATION);
}
@Override
public void onBackPressed() {
backbtnPress = true;
super.onBackPressed();
}
}
CODIGO PARA DAR UN FONDO A LA PANTALLA DE LA APLICACION
android:background"@drawable/fondo2"
Depende de el nombre que se la ponga a la imgen que se quiere de fondo
CÓDIGO PARA DAR LA ORDEN DE QUE SE REALICEN LAS OPERACIONES MATEMÁTICAS EN EL PROGRAMA
import
com.example.calculator.R;
import
android.os.Bundle;
import
android.app.Activity;
import android.view.Menu;
import
android.view.View;
import
android.widget.EditText;
import
android.widget.TextView;
import
android.widget.CheckBox;
public
class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu
menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void Resultado(View view) {
EditText
et1=(EditText)findViewById(R.id.et1);
EditText
et2=(EditText)findViewById(R.id.et2);
EditText
et3=(EditText)findViewById(R.id.et3);
CheckBox checkBox1=(CheckBox)findViewById(R.id.checkBox1);
CheckBox
checkBox2=(CheckBox)findViewById(R.id.checkBox2);
CheckBox
checkBox3=(CheckBox)findViewById(R.id.checkBox3);
CheckBox
checkBox4=(CheckBox)findViewById(R.id.checkBox4);
CheckBox checkBox5=(CheckBox)findViewById(R.id.checkBox5);
int
nro1=Integer.parseInt(et1.getText().toString());
int nro2=Integer.parseInt(et2.getText().toString());
if (checkBox1.isChecked()==true) {
int
suma=nro1+nro2;
String
resu=String.valueOf(suma);
et3.setText(resu);
}
else
if
(checkBox2.isChecked()==true) {
int
resta=nro1-nro2;
String
resu=String.valueOf(resta);
et3.setText(resu);
}
else
if
(checkBox3.isChecked()==true) {
int
mul=nro1*nro2;
String
resu=String.valueOf(mul);
et3.setText(resu);
}
else
if
(checkBox4.isChecked()==true) {
int
div=nro1/nro2;
String
resu=String.valueOf(div);
et3.setText(resu);
}
else
if
(checkBox5.isChecked()==true) {
int
ele=nro1*nro1;
String
resu=String.valueOf(ele);
et3.setText(resu);
}
}
}

No hay comentarios:
Publicar un comentario