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
    

      

      

  • 相关阅读:
    完全自主创建Wrapper Tomcat容器
    python新手菜鸟之基础篇
    使用python抓取数据之菜鸟爬虫1
    简单实现Python调用有道API接口(最新的)
    演示嵌套函数定义及使用装饰器
    纯手工搭建VS 2017(社区 免费版)离线安装包
    C#中的PropertyGrid绑定对象,通过改变某一值而动态设置部分属性的特性
    WinForm 画布的标尺和网格
    Open Source
    动态链接库-Win32 DLL的说明
  • 原文地址:https://www.cnblogs.com/pengmn/p/14958086.html
Copyright © 2011-2022 走看看