如何通过在 android 的 hexdec 中选择开始和结束颜色来创建 ColorSlider
How to create a ColorSlider by picking start and end color in hexdec in android
我想在 Android 中创建一个搜索栏,起始颜色为“00AA10”,结束颜色为“0FFF99”,然后我可以通过递增此十六进制十进制值来更改颜色并获得通过计算 2 种给定颜色的距离来获得新颜色。
String hexString= "00AA10";
int a=Integer.parseInt(hexString, 16);
//if you want increment by 5 means i++ replace i=i+5
for(int i=0;i<100;i++)
{
i= a+i;
String incHex = Integer.toHexString(i);
seekBar.setBackgroundColor(Color.parseColor("#"+incHex));
}
String hexStringStart= "00AA10";
int a=Integer.parseInt(hexStringStart, 16);
String hexStringEnd= "0FFF99";
int b=Integer.parseInt(hexStringEnd, 16);
int discrete=0;
int start_pos=0;
int start_position=0;
int start=0;
int end=100;
SeekBar seek= new SeekBar(getContext());
start=a; // need to give starting value of SeekBar
end=b; // need to give end value of SeekBar
start_pos=a; // need to give starting position value of SeekBar
start_position=(int) (((start_pos-start)/(end-start))*100);
discrete=start_pos;
seek.setProgress(start_position);
seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
String colorString = String.format("%06X", (0xFFFFFF & discrete));
// TODO Auto-generated method stub
Toast.makeText(getContext(), "Color = "+colorString, Toast.LENGTH_SHORT).show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
// To convert it as discrete value
float temp=progress;
float dis=end-start;
discrete = (int) (start+((temp/100)*dis));
}
});
}
我想在 Android 中创建一个搜索栏,起始颜色为“00AA10”,结束颜色为“0FFF99”,然后我可以通过递增此十六进制十进制值来更改颜色并获得通过计算 2 种给定颜色的距离来获得新颜色。
String hexString= "00AA10";
int a=Integer.parseInt(hexString, 16);
//if you want increment by 5 means i++ replace i=i+5
for(int i=0;i<100;i++)
{
i= a+i;
String incHex = Integer.toHexString(i);
seekBar.setBackgroundColor(Color.parseColor("#"+incHex));
}
String hexStringStart= "00AA10";
int a=Integer.parseInt(hexStringStart, 16);
String hexStringEnd= "0FFF99";
int b=Integer.parseInt(hexStringEnd, 16);
int discrete=0;
int start_pos=0;
int start_position=0;
int start=0;
int end=100;
SeekBar seek= new SeekBar(getContext());
start=a; // need to give starting value of SeekBar
end=b; // need to give end value of SeekBar
start_pos=a; // need to give starting position value of SeekBar
start_position=(int) (((start_pos-start)/(end-start))*100);
discrete=start_pos;
seek.setProgress(start_position);
seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
String colorString = String.format("%06X", (0xFFFFFF & discrete));
// TODO Auto-generated method stub
Toast.makeText(getContext(), "Color = "+colorString, Toast.LENGTH_SHORT).show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
// To convert it as discrete value
float temp=progress;
float dis=end-start;
discrete = (int) (start+((temp/100)*dis));
}
});
}