Convert String to Drawable

后端 未结 8 2225
我在风中等你
我在风中等你 2021-02-20 12:31

I want to raise a notification showing an icon in the status bar - so far so good, but actually I would like this icon to be a 3 character String.

So my question is: Is

相关标签:
8条回答
  • 2021-02-20 13:12

    I have used a workaround and it worked properly for me.

    First i convert the string to bitmap and then convert it to a drawable, here is the code:

    byte [] encodeByte=Base64.decode(":",Base64.DEFAULT);
    Bitmap bitmap=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);      
    Drawable d = new BitmapDrawable(bitmap);
    

    Hope it helps!

    0 讨论(0)
  • 2021-02-20 13:12
    try  {
    
        InputStream inputStream = new URL(Your imageWebAddress).openStream();
    
        drawable = Drawable.createFromStream(inputStream, null);
        inputStream.close();
      }
      catch (MalformedURLException ex) { }
      catch (IOException ex) { }
      layout.setBackground(drawable);
    
    0 讨论(0)
  • 2021-02-20 13:20

    Short: No, you can't.

    Long: The notification needs a R.drawable.something for the icon and you can't create it on runtime.

    0 讨论(0)
  • 2021-02-20 13:21

    you can make your own custom drawable that would work just like the textview widget except it is a drawable instead of a view. The textview class is just a container for the drawable that contains the text.

    0 讨论(0)
  • 2021-02-20 13:27

    Have you looked at the API Demos > App > Notifications > Status Bar?

    If you have limited number of String options (like Smileys) you can create drawables for each of those Strings.

    0 讨论(0)
  • 2021-02-20 13:30

    No you can not, I thought you could use the same method as here: Combine image and text to drawable, but you can't, as the notification takes a drawable id, not a drawable object.

    0 讨论(0)
提交回复
热议问题