Pesquisar




Author Image
Desenvolvimento em Foco Programação Contact Me

AIDE - IMPLEMENTANDO GRÁFICOS E EFEITOS AO MEU PRIMEIRO PROJETO.









Imagens colocadas na Pasta - drawable













efeito_botao.xml - criado na Pasta - drawable

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@drawable/b1" />
    <item android:drawable="@drawable/b2" />
</selector>






Sons colocados na Pasta - raw





splash.xml colocado na Pasta - layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@android:color/background_dark">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/def" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:background="@drawable/thiengo"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="39dp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:id="@+id/imageView3"
        android:background="@drawable/ameidapps"
        android:layout_below="@+id/imageView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="45dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/efeito_botao"
        android:text="Avançar"
        android:id="@+id/avancar"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/efeito_botao"
        android:text="Fechar"
        android:id="@+id/fechar"
        android:layout_alignTop="@+id/avancar"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>



main.xml colocado na Pasta - layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@android:color/background_dark">

<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/relativeLayout2">

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/efeito_botao"
android:text="Voltar"
android:id="@+id/voltar"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>

</RelativeLayout>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/efeito_botao"
android:text="Fechar"
android:id="@+id/fechar"
android:layout_below="@+id/relativeLayout"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/efeito_botao"
android:id="@+id/tocarA"
android:layout_marginTop="112dp"
android:layout_below="@+id/relativeLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/efeito_botao"
android:id="@+id/tocarB"
android:layout_alignTop="@+id/tocarA"
android:layout_alignLeft="@+id/fechar"
android:layout_alignStart="@+id/fechar"/>

</RelativeLayout>


Splash.java colocado na Pasta - java

package com.meu.projeto;
import android.content.Intent;
import java.util.Timer;
import java.util.TimerTask;

import android.app.*;
import android.os.*;
import android.view.View;
import android.widget.*;

public class Splash extends Activity {
protected static ProgressDialog dialog ;
protected static Button avancar,fechar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
dialog = new ProgressDialog(this);
dialog.setIcon(R.drawable.ic_launcher);
dialog.setCancelable(false);
dialog.setTitle("Meu Primeiro Projeto");
dialog.setMessage("Carregando...");

avancar =(Button)findViewById(R.id.avancar);
avancar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1){
Iniciar();
dialog.show();
}
});
fechar =(Button)findViewById(R.id.fechar);
fechar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1){
Fechar();
}
});

}

// Novos Métodos
public void Iniciar(){
new Timer().schedule(new TimerTask() {
@Override
public void run() {
dialog.dismiss();
finish();
Intent tela1 = new Intent (Splash.this,
MainActivity.class);
startActivity(tela1);
}
 }, 5000);
  }

public void Fechar(){
finish();
System.exit(0);
}
}


MainActivity.java colocado na Pasta - java

package com.meu.projeto;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import android.media.*;

public class MainActivity extends Activity {
protected static Button tocarA,tocarB,voltar,fechar;
protected static MediaPlayer mediaPlayer = new MediaPlayer();

@Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

tocarA =(Button)findViewById(R.id.tocarA);
tocarA.setText("Tocar A");
tocarA.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View b2){
//onClick Objeto mediaPlayer chamado
mediaPlayer.stop();
mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.soma);
mediaPlayer.start();
Toast.makeText(getApplicationContext(),
"Som - A: " +String.valueOf(getString(R.raw.soma)),Toast.LENGTH_SHORT)
.show();
}
});

tocarB =(Button)findViewById(R.id.tocarB);
tocarB.setText("Tocar B");
tocarB.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View b3){
mediaPlayer.stop();
mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.somb);
mediaPlayer.start();
Toast.makeText(getApplicationContext(),
"Som - B: " +String.valueOf(getString(R.raw.somb)),Toast.LENGTH_SHORT)
.show();

}
});


//Novos Botões

voltar =(Button)findViewById(R.id.voltar);
voltar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1){
finish();
Intent tela1 = new Intent (MainActivity.this,
Splash.class);
startActivity(tela1);
Toast.makeText(getApplicationContext(),
"Voltou à tela 1",Toast.LENGTH_SHORT)
.show();
}
});

fechar =(Button)findViewById(R.id.fechar);
fechar.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1){
finish();
System.exit(0);
}
});
    }
}



Nenhum comentário:

Postar um comentário

Obrigado por comentar, volte sempre!

Seguidores

Não encontrou o que procura ?