zoukankan      html  css  js  c++  java
  • Set mipmap image as linearLayout background programmatically

    ll.setBackgroundResource(R.mipmap.my_image);
    or
    
    ll.setBackground(ResourcesCompat.getDrawable(getResources(), R.mipmap.my_image, null))
    

      

    Set mipmap image as linearLayout background programmatically
    Asked 4 years, 4 months ago
    Active 3 years, 8 months ago
    Viewed 2k times
    
    
    0
    
    
    I have a .png image in mipmap directory. know I want to set this image as the linearLayout background programmatically. and after some processes remove it.
    
    target SDK : 23
    min SDK    : 14
    which function shall I use?
    
    this can change background color:
    
    ll.setBackgroundColor(getResources().getColor(R.color.color_mtn));
    but where is background image?
    
    android
    background-image
    Share
    Improve this question
    Follow
    edited Feb 27 '17 at 11:22
    asked Feb 27 '17 at 11:13
    
    Shima Erfan
    30511 gold badge55 silver badges1717 bronze badges
    l1.setBackgroundResource(getResources().getDrawable(R.mipmap.your_image)); – pankaj khedekar Feb 27 '17 at 11:20
    Add a comment
    2 Answers
    
    6
    
    ll.setBackgroundResource(R.mipmap.my_image);
    or
    
    ll.setBackground(ResourcesCompat.getDrawable(getResources(), R.mipmap.my_image, null))
    Share
    Improve this answer
    Follow
    answered Feb 27 '17 at 11:17
    
    lelloman
    12.8k55 gold badges5656 silver badges7777 bronze badges
    Add a comment
    
    0
    
    Both are Working
    
    iv_pic_image.setImageResource(R.mipmap.generic_product_4);
    
    or
    
    iv_pic_image.setImageDrawable(getResources().getDrawable(R.mipmap.generic_product_4));
    Share
    Improve this answer
    Follow
    answered Oct 30 '17 at 6:20
    
    Keshav Gera
    8,42611 gold badge5757 silver badges4444 bronze badges
    Add a comment
    Your Answer

    https://stackoverflow.com/questions/42484360/set-mipmap-image-as-linearlayout-background-programmatically
    

      

      

  • 相关阅读:
    金蝶问题:不能保存已审核的单据
    在代码中设置cxTreeList按多列排序
    日积月累篇:生产任务单
    sp_reset_connection
    日积月累篇:仓库流程
    使用FreeMarker生成Word文档 仅此而已
    ASP格式化时间日期(二)
    省市区三级联动连接数据库
    利用SQL语句进行添加、删除、修改字段,表与字段的基本操作,数据库备份等
    ASP截取字数(二)
  • 原文地址:https://www.cnblogs.com/pengmn/p/14958086.html
Copyright © 2011-2022 走看看