There're 2 RadioButtons in my application. They are both displayed in xml in AndroidStudio, but when I run the app on the phone, they disappear. It's not because of their positioning or some random function - for the sake of testing I placed another RadioButton and didn't do anything with it. When I ran the app, it didn't get displayed either. The only problem I see is something with styles, but they seem to be fine. I'll still post the codes:
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="@+id/maleBtn" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="@+id/femaleBtn"
android:layout_toRightOf="@+id/maleBtn"
android:layout_marginLeft="10dp" />
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.ActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="My.Button" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">false</item>
</style>
</resources>
try this code, I believe the some where in your layout parent of your RadioButton
is changing the visibility or Due to orientation of the parent you are not able to see the RadioButton
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/radioButton_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:text="Male" />
<RadioButton
android:id="@+id/radioButton_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:text="Female" />
</RadioGroup>