J'ai travaillé sur cette application de conversion de température sur Android Studio et j'ai du mal à faire un bouton arrondi. J'ai fait mes recherches et l'utilisation du fichier XML dans le dessinable est la meilleure option que j'ai. Cependant, je prévois de modifier ceci non pas dans le fichier xml d'activité principal mais par JAVA (Puisque je veux que la forme de bouton change à la forme arrondie de boîte quand cliqué individuellement)Le bouton de forme de contour arrondi ne s'affiche pas sur l'appareil
Maintenant, une partie de mon activité principale ressemble java quelque chose comme
mmBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mmSelectedClicked[0] = true;
cmSelectedClicked[0] = false;
kmSelectedClicked[0] = false;
miSelectedClicked[0] = false;
mSelectedClicked[0] = false;
ydSelectedClicked[0] = false;
inSelectedClicked[0] = false;
kmBtn.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
cmBtn.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
miBtn.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
mBtn.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
ydBtn.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
inBtn.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
if(mmSelectedClicked[0] == true){
view.setBackground(ColorDrawable.createFromPath("roundbutton"));
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
HscrollView1.smoothScrollTo((int) mmBtn.getX() - 150, 0);
}
}, 500);
} else {
}
}
});
J'ai mis:
view.setBackground(ColorDrawable.createFromPath("roundbutton"));
pour changer l'arrière-plan (étirables) au "roundbutton.xml" sous le dossier drawable. L'application fonctionne sans plantage, cependant, l'arrière-plan du bouton est affiché dans une boîte rectangulaire bordée de couleurs que je n'ai pas définie dans mon "roundbutton.xml".
Comme on le voit ci-dessus, quand j'initialiser mon application, xml (étirables) boutons -applied montrent que la boîte de bouton gauche (mm millimètre) avec la ligne de frontière laid. (fyi, le bouton droit est un bouton non-xml appliqué, mais cela devrait être la couleur, il devrait apparaître comme selon roundbutton.xml
Dans mon aperçu Android Studio, boîte semble montrer comme décrit (entièrement coloré aussi , pas une boîte blanche) dans mon roundbutton.xml, mais sur mon application réelle, il ne sera pas affiché
mon RoundButton code xml:.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<!-- you can use any color you want I used here gray color-->
<solid android:color="#CEF8D6"/>
<corners android:radius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
Je voudrais avoir mon image drawable en tant qu'arrière-plan d'un bouton, et lorsque j'appuie sur d'autres boutons, il retournera à #FFFFFFFF normal
J'apprécierais grandement si vous avez une solution à ce problème. :-)
Seulement androïde: rayon = "10DP" est enought dans les coins – Nepster
view.setBackground (ColorDrawable.createFromPath ("RoundButton")); déclaration est fausse. vous pouvez le définir comme view.setBackgroundResource (R.drawable.roundbutton); – Nepster