2016-10-07 27 views
0

ボタンの下にテキストがあります。ボタンクリックでテキストビュー内のテキストの色を変更するにはどうすればよいですか?セレクタに追加する必要がありますか?またはJavaコード内ですか?ここでボタンのクリックでtextViewテキストの色を変更する方法

は、セレクタです:

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

<item android:state_pressed="false"> 
    <shape android:shape="oval"> 
     <solid 
      android:color="@color/blue_800"/> 
    </shape> 
</item> 
<item android:state_pressed="true"> 
    <shape android:shape="oval"> 
     <solid android:color="@color/blue_300"/> 
    </shape> 
</item> 

とレイアウトこれまで:

<LinearLayout 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<Button 
    android:id="@+id/imageUploader1" 
    android:background="@drawable/round_button" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_marginRight="2dp" 
    android:layout_marginLeft="2dp"/> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Main" 
    android:layout_gravity="center"/> 
</LinearLayout> 

答えて

2

単にあなたのJavaコードでこれを適用

button.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     textView.setTextColor(Color.BLUE); 
    } 
}); 
+0

Pff、ありがとう! – user6456773

関連する問題