2016-04-09 14 views
1

私はトグルボタンを使用してAPI11に戻っています。問題はこの標準ですToggle Buttomは灰色がかった背景色をしているようですが、背景)。Androidトグルボタン - 背景色

Example picture

私がしようとしてきた:

android:background="@color/white" 
android:background="@null" 

が、その後、私はまた、私は維持したいインジケータライトを、失います。 トグルボタンの背景色を変更する(自分のセレクタを作成する)ことについていくつかの回答を見たことがありますが、これらのインジケータも消えているようです。

これは、レイアウトの関連する部分である:

<LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <Button 
       android:id="@+id/event_bottom_sheet_attenders" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:background="@color/white" 
       android:drawableLeft="@drawable/state_list_people_person_bottom_sheet" 
       android:drawableStart="@drawable/state_list_people_person_bottom_sheet" 
       android:gravity="center" 
       android:padding="10dp" 
       android:text="Attenders" 
       android:textColor="@color/material_teal_500" /> 

      <ToggleButton 
       android:id="@+id/event_bottom_sheet_toggle" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:checked="true" 
       android:gravity="center" 
       android:padding="10dp" 
       android:textColor="@color/material_teal_500" 
       android:textOff="Not going" 
       android:textOn="Going" /> 

</LinearLayout> 

は、どのように私はこれを修正については行くのですか?

ありがとうございます。

答えて

1

最初に異なるandroid themesを見ることが考えられます。

あなたの好みに最適なテーマを選択するか、特別なものが必要な場合は自分のテーマをカスタマイズできます。

あなたが説明したところから、Android Lightテーマを試すことができます。あなたの活動情報は、次のような変更:

<activity android:theme="@android:style/Theme.Light"> 

P/S:また、テーマを適用すると、あなたのアプリがあまりにも多くの一貫見えることができます。

+0

私の活動は暗いテーマを使用していますが、私はそれを保ちたいと思います。私がこれを表示しているところは、一番下のシートのダイアログです。私はちょうどそれにテーマを適用することができますどのような方法ですか? – CounterFlame

+0

この場合、カスタムドロウアブルを作成してバックグラウンドとして設定する必要があります。 – sihao

+0

ええ、ええ、それも考えた。ライトテーマで普通に使われているドロアブルがどのように見つかるかわからないので、そこからコピーして必要に応じて微調整するだけです。 – CounterFlame

0

チェックこのアウト: - あなたが必要と

ToggleButton Btn=new ToggleButton(this);// or get it from the layout by ToggleButton Btn=(ToggleButton) findViewById(R.id.IDofButton); 
    Btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 

     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
      // TODO Auto-generated method stub 
      if(isChecked) 
       buttonView.setBackgroundColor(Color.GREY); 
      else buttonView.setBackgroundColor(Color.WHITE); 
     } 
    }); 

はそれに応じてそれを実行してください。

これが役に立ちます。 :)

+0

私はこれを行うと、インジケータライト(最下部のシアンバー) 。 – CounterFlame