1
我想在Android SeekBar的大拇指中顯示當前進度點的值。這是我迄今試過的:如何在SeekBar拇指內顯示Android SeekBar progressChanged值?
SeekBar progBar = (SeekBar)FindViewById(Resource.Id.seekBar1);
progBar.ProgressChanged += (object sender, SeekBar.ProgressChangedEventArgs e) =>
{
if (e.FromUser)
{
Drawable d = ContextCompat.GetDrawable(this, Resource.Drawable.thumb);
Bitmap bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.thumb);
Bitmap bmp = bitmap.Copy(Bitmap.Config.Argb8888, true);// this line gives me a System.NullReferenceException: Object reference not set to an instance of an object. error
Canvas c = new Canvas(bmp);
Canvas c = new Canvas(bmp);
string text = Integer.ToString(progBar.Progress);
Paint p = new Paint();
p.SetTypeface(Typeface.DefaultBold);
p.TextSize = 14;
p.Color = Color.White;
int width = (int)p.MeasureText(text);
int yPos = (int)((c.Height/2) - ((p.Descent() + p.Ascent())/2));
c.DrawText(text, (bmp.Width - width)/2, yPos, p);
progBar.SetThumb(new BitmapDrawable(Resources, bmp));
}
};
然後,當我得到了可繪製d類型時,它是一個漸變可繪製。我研究過,但我無法找到一種方法來將梯度Drawable轉換爲位圖。