09.02.2017 Views

creez-des-applications-pour-android

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3 Création d’interfaces graphiques<br />

}<br />

}<br />

retour = resources.getDrawable(R.drawable.clin);<br />

else if(smiley.compareTo("smile") == 0)<br />

retour = resources.getDrawable(R.drawable.smile);<br />

else<br />

retour = resources.getDrawable(R.drawable.heureux);<br />

// On délimite l'image (elle va de son coin en haut à gauche à son coin en bas à dr<br />

retour.setBounds(0, 0, retour.getIntrinsicWidth(), retour.getIntrinsicHeight());<br />

return retour;<br />

3.5.4.2.2 L’activité Enfin, le principal, le code de l’activité :<br />

public class NotepadActivity extends Activity {<br />

/* Récupération <strong>des</strong> éléments du GUI */<br />

private Button hideShow = null ;<br />

private Slider slider = null ;<br />

private RelativeLayout toHide = null ;<br />

private EditText editer = null ;<br />

private TextView text = null ;<br />

private RadioGroup colorChooser = null ;<br />

private Button bold = null ;<br />

private Button italic = null ;<br />

private Button underline = null ;<br />

private ImageButton smile = null ;<br />

private ImageButton heureux = null ;<br />

private ImageButton clin = null ;<br />

/* Utilisé <strong>pour</strong> planter les smileys dans le texte */<br />

private SmileyGetter getter = null ;<br />

/* Couleur actuelle du texte */<br />

private String currentColor = "#000000" ;<br />

@Override<br />

public void onCreate(Bundle savedInstanceState) {<br />

super.onCreate(savedInstanceState);<br />

setContentView(R.layout.main);<br />

getter = new SmileyGetter(this);<br />

// On récupère le bouton <strong>pour</strong> cacher/afficher le menu<br />

hideShow = (Button) findViewById(R.id.hideShow);<br />

// Puis on récupère la vue racine de l'application et on change sa couleur<br />

hideShow.getRootView().setBackgroundColor(R.color.background);<br />

// On rajoute un Listener sur le clic du bouton…<br />

172

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!