动作栏图标图像以编程方式

时间:2014-10-27 02:46:16

标签: android android-actionbar

我在滚动滚动视图时使用此代码将alpha和字体设置为我的操作栏视图。

    int upId = Resources.getSystem().getIdentifier("icon", "id", "android");
    if (upId > 0) {
        ImageView up = (ImageView) findViewById(upId);
        up.setImageResource(R.drawable.ic_launcher);
    }


    int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
    abTitle = (TextView) findViewById(titleId);
    abTitle.setTextColor(Color.BLACK);
    abTitle.setAlpha(0);
    abTitle.setTypeface(tf);
  • 嗯,到目前为止一直很好,但我想尝试获取操作栏图标,而且我无法获取图像视图的标识符。任何人都可以给我一个暗示吗?

在你提问之前:我这样做是因为我想让我的应用程序保持最低的sdk。

1 个答案:

答案 0 :(得分:0)

解决方案:

    logo = getResources().getDrawable(R.drawable.logo_degradee);
    logo.setAlpha(0);

    getActionBar().setLogo(logo);

更容易预期