Codes Sources Session Normale

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 2

CODE SOURCE APK SESSION NORMALE

MAINACTIVITY.JAVA
package com.example.ivan.sessionnormale;
import android.graphics.Color;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.QuickContactBadge;
import static android.graphics.Color.YELLOW;
public class MainActivity extends AppCompatActivity {
int k = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.mon_button);
final ConstraintLayout constraintLayout = (ConstraintLayout)
findViewById(R.id.root);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (k==0){
k++;
constraintLayout.setBackgroundColor(Color.BLUE);
}
else {
if (k==1){
k++;
constraintLayout.setBackgroundColor(Color.RED);
}
else {
k--;
constraintLayout.setBackgroundColor(Color.BLUE);
}
}
}
});
}
}

ACTIVITY MAIN XML

<?xml version="1.0" encoding="utf-8"?>


<android.support.constraint.ConstraintLayout
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:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="18dp"
android:text="CHANGE DE COULEUR"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="66dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/cl"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.68"
tools:text="CHANGE DE COULEUR" />
</android.support.constraint.ConstraintLayout>
}

You might also like