简体   繁体   English

在android中按下按钮时如何调用颜色选择器?

[英]How do I call a color picker when a button is pressed in android?

The button has a predefined color. 该按钮具有预定义的颜色。 I need to show a selection of colors on pressing the button. 我需要在按下按钮时显示多种颜色。 And then give the button the selected background color. 然后为按钮提供所选的背景色。 I have just started android programming. 我刚刚开始进行android编程。 Any help will be much appreciated. 任何帮助都感激不尽。

You need to use a color picker for this purpose. 为此,您需要使用颜色选择器。

button.setOnClickListener(new OnClickListener() {

 void onClick(View v) {
// create the color picker dialog and display it.
ColorPickerDialog dlg = new ColorPickerDialog(v.getContext(),new OnColorChangedListener()     {
      void colorChanged(int color) {
           mSelectedColor = color;
       }

   }),initialColor);
   dlg.show();
  }
});

initialColor will be replaced by mSelectedColor, the new selected color from the picker. initialColor将替换为mSelectedColor,即选择器中新选择的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM