【问题标题】:how to change EditText bottom line programmatically如何以编程方式更改 EditText 底线
【发布时间】:2015-05-06 01:39:55
【问题描述】:

我有一个将数据捆绑到另一个活动的活动。有了这些数据,我还捆绑了一个自定义颜色,我希望在活动 2 中显示 EditText 的底线。

活动一:

Bundle bundle = new Bundle();
bundle.putExtra("Color", color);

活动二:

int value = getIntent().getExtras().getInt(Color)

现在,当我从活动 1 中获取捆绑包时,我可以通过编程方式更改 EditText 的颜色吗?如果您能帮助我,我将不胜感激。

【问题讨论】:

    标签: java android xml android-activity


    【解决方案1】:

    可能是这样的,

    活动 2//

    int value = getIntent().getExtras().getInt(Color);
    // Here I assume you have defined edittext form layout file so it is not null
    editText.getBackground().setColorFilter(value, PorterDuff.Mode.SRC_ATOP);
    

    试试这个,让我知道,它是否有效。

    【讨论】:

      【解决方案2】:

      活动一

      Intent intent = new Intent(Activity1.this, Activity2.class);
      Bundle bundle  = new Bundle();
      bundle.putInt("Color", color); //Your id
      intent.putExtras(bundle); //Put your id to your next Intent
      startActivity(intent);
      finish();
      

      活动 2

      Bundle b = getIntent().getExtras();
      int value = b.getInt("Color");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-14
        • 1970-01-01
        • 1970-01-01
        • 2021-11-24
        • 1970-01-01
        • 2015-07-28
        • 1970-01-01
        • 2017-04-13
        相关资源
        最近更新 更多