【问题标题】:How to get application icon from package name and set to textview drawable top in android如何从包名称中获取应用程序图标并在android中设置为textview drawable top
【发布时间】:2017-04-28 06:05:41
【问题描述】:

我有一个应用程序,我从包名称中找到应用程序图标并将其设置为 textview drawable top。我该怎么做,请指导我。

代码:-

  try {
        Drawable icon = getPackageManager().getApplicationIcon("com.example.testnotification");
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

【问题讨论】:

  • textView drawable top是什么意思?

标签: android android-studio package drawable


【解决方案1】:

您可以尝试在 textview 上设置可绘制对象 @satish

textView.setCompoundDrawablesWithIntrinsicBounds(icon , 0, 0, 0);

【讨论】:

    【解决方案2】:

    使用PackagerManager'sgetApplicationIcon() 完成此任务:

    检索与应用程序关联的图标。如果还没有 定义一个图标,返回默认的应用图标。不返回 空。

    try {
         Drawable icon = getPackageManager().getApplicationIcon("com.example.testnotification");
         textView.setCompoundDrawablesWithIntrinsicBounds(null, icon , null, null);
      }  catch (Exception e){
         e.printStackTrace();
      }
    

    EX

    Drawable appIcon = getPackageManager().getApplicationIcon("com.google.maps");
    

    设置在可绘制的顶部

    TextView textView = (TextView) findViewById(R.id.txtDate);
    textView.setCompoundDrawablesWithIntrinsicBounds(null, R.drawable.icon, null, null);
    

    查看android:drawableTop

    setCompoundDrawablesWithIntrinsicBounds(Drawable left, Drawable top, Drawable right, Drawable bottom) 设置 Drawables(如果有的话)出现 文本的左侧、上方、右侧和下方。

    【讨论】:

    • 我有 textview 我必须将图像设置为 drawableTop
    猜你喜欢
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多