title: Wrap_Content with costume radio button?
body: <p>I have made a quiz app but I am facing problems with the radio buttons. I created a rounded background and set it as my radio button background. However, the background doesn't enlarge with the amount of text inside the radio button.</p>
  <h3>Here is an image</h3>
  <p>I cannot post an image with less than 10 reputation.
  <a href="https://i.imgur.com/5M9Y6cH.jpg" rel="nofollow noreferrer">https://i.imgur.com/5M9Y6cH.jpg</a></p>
  <p>My first post here so forgives me for any bad formatting. Thanks in advance for the advice!!</p>
  <p>Here is my XML code for a rounded button and for quiz.xml</p>
  <h2>rounded_option.xml</h2>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;selector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
      &lt;item&gt;
          &lt;shape xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; android:shape=&quot;rectangle&quot;&gt;
              &lt;solid android:color=&quot;@android:color/holo_orange_light&quot; /&gt;
              &lt;corners android:radius=&quot;150dp&quot; /&gt;
          &lt;/shape&gt;
      &lt;/item&gt;
  &lt;/selector&gt;
  </code></pre>
  <h2>quiz.xml</h2>
  <pre><code>&lt;RadioGroup
          android:id=&quot;@+id/radio_group&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_below=&quot;@id/text_view_question&quot;
          tools:ignore=&quot;RelativeOverlap&quot;&gt;
  
  
          &lt;RadioButton
              android:id=&quot;@+id/radio_button1&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginTop=&quot;25dp&quot;
              android:background=&quot;@drawable/rounded_option&quot;
              android:padding=&quot;5dp&quot;
              android:text=&quot;Option 1 \n option1 \n option&quot;
              android:textAlignment=&quot;gravity&quot;
              android:textSize=&quot;20dp&quot;
              tools:ignore=&quot;HardcodedText&quot; /&gt;
  </code></pre>
  <h3>Activity Code### A bit messy but as asked here is the full code. If I put fragments then the solution will not be found.</h3>
  <pre><code>import android.content.Intent;
  import androidx.appcompat.app.AppCompatActivity;
  import android.content.res.ColorStateList;
  import android.graphics.Color;
  
  
  import android.graphics.drawable.Drawable;
  import android.os.Bundle;
  
  
  import android.view.View;
  import android.widget.Button;
  import android.widget.RadioButton;
  import android.widget.RadioGroup;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.Collections;
  import java.util.List;
  
  
  import static android.graphics.Color.GREEN;
  import static android.graphics.Color.RED;
  
  
  
  public class QuizActivity extends AppCompatActivity {
      
      public static final String EXTRA_SCORE = &quot;extraScore&quot;;
      private TextView textViewQuestion;
      private TextView textViewScore;
      private TextView textViewQuestionCount;
      private TextView textViewCorrectAnswer;
      private RadioGroup rbGroup;
      private RadioButton rb1;
      private RadioButton rb2;
      private RadioButton rb3;
      private RadioButton rb4;
      private Button buttonConfirmNext;
      private long backPressedTime;
  
      private ColorStateList textColorDefaultRb;
      private Drawable textColorDefaultButton;
      private Drawable textColorDefaultAnswer;
  
      private List&lt;Question&gt; questionList;
      private int questionCounter;
      private int questionCountTotal;
      private Question currentQuestion;
  
      private int score;
      private boolean answered;
  
  
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_quiz);
  
          textViewQuestion = findViewById(R.id.text_view_question);
          textViewScore = findViewById(R.id.text_view_score);
          textViewCorrectAnswer = findViewById(R.id.text_view_correctAnswer);
          textViewQuestionCount = findViewById(R.id.text_view_question_count);
          rbGroup = findViewById(R.id.radio_group);
          rb1 = findViewById(R.id.radio_button1);
          rb2 = findViewById(R.id.radio_button2);
          rb3 = findViewById(R.id.radio_button3);
          rb4 = findViewById(R.id.radio_button4);
  
          buttonConfirmNext = findViewById(R.id.button_confirm_next);
  
          textColorDefaultRb = rb1.getTextColors();
          textColorDefaultButton = rb1.getBackground();
  
  
          QuizDbHelper dbHelper = new QuizDbHelper(this);
          questionList = dbHelper.getAllQuestions();
          questionCountTotal = 20;
          Collections.shuffle(questionList);
  
          showNextQuestion();
  
          buttonConfirmNext.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (!answered) {
                      if (rb1.isChecked() || rb2.isChecked() || rb3.isChecked() || rb4.isChecked()) {
                          checkAnswer();
                      } else {
                          Toast.makeText(QuizActivity.this, &quot;Please select an answer&quot;, Toast.LENGTH_SHORT).show();
                      }
                  } else {
                      showNextQuestion();
                      textViewCorrectAnswer.setText(&quot;&quot;);
                      textViewCorrectAnswer.setBackground(textColorDefaultAnswer);
                  }
              }
          });
      }
  
  
      private void showNextQuestion() {
          rb1.setTextColor(textColorDefaultRb);
          rb2.setTextColor(textColorDefaultRb);
          rb3.setTextColor(textColorDefaultRb);
          rb4.setTextColor(textColorDefaultRb);
  
  
          rb1.setBackground(textColorDefaultButton);
          rb2.setBackground(textColorDefaultButton);
          rb3.setBackground(textColorDefaultButton);
          rb4.setBackground(textColorDefaultButton);
  
  
          rbGroup.clearCheck();
  
          if (questionCounter &lt; questionCountTotal) {
              currentQuestion = questionList.get(questionCounter);
  
              textViewQuestion.setText(currentQuestion.getQuestion());
              rb1.setText(currentQuestion.getOption1());
  
              rb2.setText(currentQuestion.getOption2());
              rb3.setText(currentQuestion.getOption3());
              rb4.setText(currentQuestion.getOption4());
  
              questionCounter++;
              textViewQuestionCount.setText(&quot;Question: &quot; + questionCounter + &quot;/&quot; + questionCountTotal);
              answered = false;
              buttonConfirmNext.setText(&quot;Confirm&quot;);
          } else {
              finishQuiz();
          }
      }
  
      private void checkAnswer() {
          answered = true;
  
          RadioButton rbSelected = findViewById(rbGroup.getCheckedRadioButtonId());
          int answerNr = rbGroup.indexOfChild(rbSelected) + 1;
  
          if (answerNr == currentQuestion.getAnswerNr()) {
              score++;
              textViewScore.setText(&quot;Score: &quot; + score);
              textViewCorrectAnswer.setText(&quot;Your Answer is Correct&quot;);
              textViewCorrectAnswer.setTextColor(GREEN);
  
          }
          else {
              textViewCorrectAnswer.setText(&quot;Your Answer is Incorrect&quot;);
              textViewCorrectAnswer.setTextColor(RED);
          }
          showSolution();
      }
  
      private void showSolution() {
  
          rb1.setBackgroundColor(Color.RED);
          rb2.setBackgroundColor(Color.RED);
          rb3.setBackgroundColor(Color.RED);
          rb4.setBackgroundColor(Color.RED);
  
  
          switch (currentQuestion.getAnswerNr()) {
              case 1:
                  rb1.setBackgroundColor(GREEN);
  
                  break;
              case 2:
                  rb2.setBackgroundColor(GREEN);
  
  
                  break;
              case 3:
                  rb3.setBackgroundColor(GREEN);
  
  
                  break;
              case 4:
  
                  rb4.setBackgroundColor(GREEN);
  
  
          }
  
          if (questionCounter &lt; questionCountTotal) {
              buttonConfirmNext.setText(&quot;Next&quot;);
  
          } else {
              buttonConfirmNext.setText(&quot;Finish&quot;);
  
          }
  
      }
  
      private void finishQuiz() {
          Intent resultIntent = new Intent();
          resultIntent.putExtra(EXTRA_SCORE, score);
          setResult(RESULT_OK, resultIntent);
          finish();
      }
  
      @Override
      public void onBackPressed() {
          if (backPressedTime + 2000 &gt; System.currentTimeMillis()) {
              finishQuiz();
          } else {
              Toast.makeText(this, &quot;Press back again to finish&quot;, Toast.LENGTH_SHORT).show();
          }
  
          backPressedTime = System.currentTimeMillis();
      }
  }
  </code></pre>