0
任何人都可以看到什麼是錯我的代碼:(我甚至不能創建一個簡單的應用程序,它保持崩潰了。按下按鈕和變化的TextView顏色
哪些應用程序是要做的是,當用戶按下該按鈕的TextView將改變顏色爲紅色。
public class MainActivity extends Activity {
public TextView tv1;
public Button bt1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt1 = (Button)findViewById(R.id.button1);
tv1 = (Button)findViewById(R.id.textView1);
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
tv1.setTextColor(Color.BLACK);
}
});
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:text="TextView" />
哦DUH!傻MEEE! – Ket