2017-08-18 66 views
0

ボタンをクリックしてタイトルバーの色を変更する方法。ボタンの1つをクリックすると、アプリケーション内のすべてのアクティビティのタイトルバーの色を変更する必要があります。タイトルバーの色

<?xml version="1.0" encoding="utf-8"?> 

    <RadioGroup 
    xmlns:android="schemas.android.com/apk/res/android"; 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
     <RadioButton 
      android:id="@+id/radio_blue" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/pirates" 
      android:onClick="onRadioButtonClicked"/> 
     <RadioButton 
      android:id="@+id/radio_red" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/ninjas" 
      android:onClick="onRadioButtonClicked"/> 
    </RadioGroup> 
+0

はあなたのコードをポスト.. –

+0

の<?xml version = "1.0" エンコード= "UTF-8"?> user8140800

答えて

0

あなたがコメントで提供されているコードは:クリック時のイベントを処理するために

<RadioGroup 
    xmlns:android="schemas.android.com/apk/res/android"; 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <RadioButton 
     android:id="@+id/radio_blue" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/pirates" 
     android:onClick="onRadioButtonClicked"/> 

    <RadioButton 
     android:id="@+id/radio_red" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/ninjas" 
     android:onClick="onRadioButtonClicked"/> 

</RadioGroup> 

は、あなたがアクションを処理するために、Activityクラスを使用する必要があります。

あなたが開始するには、このような何かを行うことができます。

public class MainActivity extends Activity { 
    TextView title; 
    RadioButton red_button, blue_button, ...; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.[Your XML Name]); 


     //Getting Widget References 
     title = (TextView) findViewById(R.id.title); 
     red_button = (RadioButton) findViewById(R.id.radio_red); 


     //Handle OnClick Events 
     red_button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       title.setTextColor(Color.parseColor("#FF0000")); 
      } 
     }); 
    } 
} 
関連する問題