-1

CheckBox と TextView を含む LinearLayout があります。CheckBox が押されたときに TextView を強調表示したい。

レイアウトとセレクター (ドローアブル フォルダー内)

<LinearLayout
        android:orientation="vertical"
        android:gravity="center" >
        <CheckBox
            android:id="@+id/chkPlayStop"
            android:button="@drawable/play_stop_state" />
        <TextView
            android:id="@+id/tvPlayStop"
            android:clickable="true"
            android:textColor="@drawable/text_view_state" />

</LinearLayout>

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:color="@color/white" android:state_pressed="true"/>
    <item android:color="@color/grey" />
</selector>

ターゲット: レイアウト内をタップすると、チェックボックスの状態が変化し、テキストビューが強調表示されます。

ありがとう。

4

3 に答える 3

0

テキストの色を変更したり、背景を配置したり、太字などのテキストタイプを変更したりして、テキストビューを強調表示できます.

背景を変更するには、 を使用できますtextView.setBackgroundColor(your color code)

テキストタイプを変更するには、使用できますtextView.setTypeface(null,Typeface.BOLD)

テキストの色を変更するには、を使用できますtextView.setTextColor(your color code)

checkChangedListener内の上記の回答に示されている場所でこのコードを使用してください。

于 2013-01-22T07:16:29.590 に答える
0

次 のように設定する必要がありOnCheckedChangeListenerます。checkbox

checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
    {
        if (isChecked)
        {
            //Highlight the text
            textView.setTypeface(null, Typeface.BOLD_ITALIC);
        } else
        {
            //Unhighlight the text
            textView.setTypeface(null, Typeface.NORMAL);
        }
    }
});
于 2013-01-22T07:08:31.870 に答える
0

次のコードを試してください。

TextView textView = (TextView) findViewById(R.id.yourTextView);
cb = (CheckBox) findViewById(R.id.yourCheckBox);

cb.setOnClickListener(new OnClickListener() {

  @Override
  public void onClick(View v) {
    if (((CheckBox) v).isChecked()) {
        textView.setBackgroundColor(Color.RED);
    }else{
        textView.setBackgroundColor(Color.BLACK);
    }

  }
});

テキストビューを強調表示する方法が正確にわからないため、例には新しい背景色のみが含まれています。

于 2013-01-22T07:09:09.677 に答える