Comment puis-je modifier la largeur de trait d'un bouton rectangle lorsque j'appuie sur le bouton?Comment modifier la largeur de trait d'un rectangle de forme par programme
J'ai créé un fichier xml dans un dossier pouvant être tracé pour mon bouton personnalisé.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="9dp"/>
<gradient
android:angle="45"
android:centerX="9%"
android:centerColor="#84edb2"
android:startColor="#07e7cb"
android:endColor="#b0ede3"
android:type="linear"
/>
<size
android:width="40dp"
android:height="30dp"
/>
<stroke
android:width="2dp" // I want to change this programmatically.
android:color="#2f7E87"
/>
</shape>
Ci-dessous est mon code java. Je souhaite modifier la largeur de trait du bouton lorsque j'appuie sur le bouton.
public static void buttonEffect(View button){
button.setOnTouchListener(new View.OnTouchListener() {
ShapeDrawable circle = new ShapeDrawable(new OvalShape());
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
Button view = (Button) v;
int col = Color.parseColor("#40E0D0");
view.getBackground().setColorFilter(col, PorterDuff.Mode.SCREEN);
v.invalidate();
break;
}
case MotionEvent.ACTION_UP:
// Your action here on button click
case MotionEvent.ACTION_CANCEL: {
Button view = (Button) v;
view.getBackground().clearColorFilter();
view.invalidate();
break;
}
}
return true;
}
});
}
Je suis nouveau android pouvez-vous me montrer comment faire que je ne sais pas que –