5
Why do buttons I create in xml not appear on Avd? In the layout they appear with a gray color, but when I touch to run in the emulator they are simply invisible. If I put some text on the button, the text appears, but the button does not. I’m following the tutorial to create this game and did nothing different, however mine is like this.
my xml file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:tag="quadrado1"
android:onClick="clickQuadrado" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:tag="quadrado2"
android:onClick="clickQuadrado" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:tag="quadrado3"
android:onClick="clickQuadrado" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:tag="quadrado4"
android:onClick="clickQuadrado" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:tag="quadrado5"
android:onClick="clickQuadrado" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:tag="quadrado6"
android:onClick="clickQuadrado" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:tag="quadrado7"
android:onClick="clickQuadrado" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:tag="quadrado8"
android:onClick="clickQuadrado" />
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:tag="quadrado9"
android:onClick="clickQuadrado" />
</LinearLayout>
</LinearLayout>
It is interesting also you show the code that is on
main.xml
– Paulo Rodrigues
Gustavo, unless you have other definitions in your
Activity
For these buttons, all you do is just define dimensions and click action practically. You need a background, a text or something like that. For that you need the propertiesandroid:background
orandroid:text
, for example. To contextualize, you have the link of this tutorial that is following?– Paulo Rodrigues
Okay, thank you. I am following the tutorial of the channel eXcript https://www.youtube.com/watch?v=FsJkaAnd9uY. Another question, when I give a margin in the first Linear Layout (most external), the changes are applied only in the XML preview, the emulator is the same, unless I apply the changes from the second Linear layout, then it works right. Only then you’d cost more lines... Thank you
– Gustavo
I forgot to comment that in the tutorial I mentioned in which I am following, it does not apply any background to Buttons, which I thought would be some configuration error in my.
– Gustavo
Gustavo, take a look if it is not the theme you are using that is making the button invisible (because they have the same color). What happens when you press the place where the button should be? He replies?
– bupereira
Good Afternoon @Gustavo, I tested your xml and it’s showing all the buttons. I believe it’s something you’re doing in your class. Any questions I’m willing to help you.
– Eduardo Binotto
Gustavo, I tested it here and it’s working fine. But anyway, if it doesn’t appear there, you can try changing the color of the buttons. Clicking on the button>going to properties (right corner of the screen)>background>color.. So you can set a different color. If the buttons are the same color as the theme, this will already solve. Also check that your java class has no setVisibility(View.INVISIBLE) method; ..
– CristianCotrena