我有許多不同顏色名稱的按鈕。選擇一個按鈕android
yellow - red - blue
我想,當一個用戶點擊它創建它周圍的邊框(選擇按鈕),在我的活動結束後我還有一個按鈕,保存所選顏色的用戶。
<Button
android:text="Yellow"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:id="@+id/button1" />
<Button
android:text="Red"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:id="@+id/button2" />
<Button
android:text="SAVE"
android:layout_width="111dp"
android:layout_height="wrap_content"
android:id="@+id/buttonsave" />
的Java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.color);
Button btnYellow;
btnYellow = (Button) findViewById(R.id.button1);
Button btnRed;
btnRed = (Button) findViewById(R.id.button2);
Intent intent = getIntent();
String url2 = intent.getStringExtra("image");
btnYellow.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});
}
我怎麼能選擇一個按鈕,當用戶點擊它,並得到一個值(紅,綠,RED1),當用戶點擊保存?
您可以點擊事件更改按鈕的背景顏色 –
您需要的單選按鈕或複選框,而不是常規按鈕 –
首先我想選擇一個按鈕,當用戶點擊,如:紅色。他們,當他點擊「保存」時,我會顯示一條消息,例如「紅色」。 @Chetan –