Ich habe zwei TextViews horizontal nebeneinander angeordnet und sie sind in einem Rechteck mit abgerundeten Ecken.Hintergrund von zwei TextView alternativ ändern
Ich möchte:
- den Hintergrund ändern, die standardmäßig keine-weiß wenn gedrückt oder angeklickt und zurück zu Standard, wenn der zweite Textview ist geklickt oder gepresst,
- die Polsterung, die zwischen der Form und dem Text ist weiß wenn gedrückt und bac k zu Standard, wenn die anderen
- die Textfarbe ausgewählt ist schwarz zu gehen, wenn der Hintergrund wissen
XML-Code der beiden Textviews geht:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:background="@drawable/toggle"
android:id="@+id/l1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coach"
android:paddingLeft="5dp"
android:textColor="#ffffff"
android:id="@+id/TV"
android:layout_gravity="center_horizontal"
android:layout_marginRight="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Client"
android:paddingRight="5dp"
android:textColor="#ffffff"
android:id="@+id/TV1"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
_____Java Code________
package com.example.jhang.sample;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import static android.R.color.black;
import static android.R.color.white;
/**
* Created by jhang on 5/2/2016.
*/
public class Activity1 extends Activity implements View.OnClickListener {
TextView coach, client, about, privacy, faq, contact,login;
LinearLayout l1;
int count=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
coach=(TextView)findViewById(R.id.TV);
client=(TextView)findViewById(R.id.TV1);
about=(TextView)findViewById(R.id.TV2);
privacy=(TextView)findViewById(R.id.TV3);
faq=(TextView)findViewById(R.id.TV4);
contact=(TextView)findViewById(R.id.TV5);
login=(TextView)findViewById(R.id.button);
l1=(LinearLayout)findViewById(R.id.l1);
coach.setOnClickListener(this);
client.setOnClickListener(this);
about.setOnClickListener(this);
privacy.setOnClickListener(this);
faq.setOnClickListener(this);
contact.setOnClickListener(this);
login.setOnClickListener(this);
l1.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
if (count==0)
{
coach.setBackgroundColor(Color.WHITE);
coach.setTextColor(Color.BLACK);
count=1;
}
else if (count==1)
{
client.setBackgroundColor(Color.WHITE);
client.setTextColor(Color.BLACK);
count=0;
}
}
}
Zeigen Sie, was Sie getan haben weit –
können Sie Ihr Java-Code anzeigen ? –