• Android


    #给textView 添加文字颜色
        setTextColor(0xFF0000FF);  
        //0xFF0000FF是int类型的数据,分组一下0x|FF|0000FF,0x是代表颜色整 数的标记,ff是表示透明度,0000FF表示颜色,注意:这里0xFF0000FF必须是8个的颜色表示,不接受0000FF这种6个的颜色表示。 
        setTextColor(Color.rgb(255, 255, 255));  
        setTextColor(Color.parseColor("#FFFFFF"));    
        //还有就是使用资源文件进行设置  
        setTextColor(this.getResources().getColor(R.color.blue));  
        //通过获得资源文件进行设置。根据不同的情况R.color.blue也可以是R.string.blue或者  
        //另外还可以使用系统自带的颜色类  
        setTextColor(android.graphics.Color.BLUE); 


    #给textView 添加背景色,背景图片
        setBackgroundResource:通过颜色资源ID设置背景色。
        setBackgroundColor:通过颜色值设置背景色。
        setBackgroundDrawable:通过Drawable对象设置背景色。

        下面分别演示如何用这3个方法来设置TextView组件的背景
        setBackgroundResource方法设置背景:
        textView.setBackgroundResource(R.color.background);

        setBackgroundColor方法设置背景:
        textView.setBackgroundColor(android.graphics.Color.RED);

        setBackgroundDrawable方法设置背景:
        Resources resources=getBaseContext().getResources();
        Drawable drawable=resources.getDrawable(R.color.background);
        textView.setBackgroundDrawable(drawable);


    #给Textview设置Drawable图标
        参考:https://github.com/Carson-Ho/Search_Layout/blob/master/searchview/src/main/java/scut/carson_ho/searchview/EditText_Clear.java

        // 作用:在EditText上、下、左、右设置图标(相当于android:drawableLeft=""  android:drawableRight="")
        // 注1:setCompoundDrawablesWithIntrinsicBounds()传入的Drawable的宽高=固有宽高(自动通过getIntrinsicWidth()& getIntrinsicHeight()获取)
        // 注2:若不想在某个地方显示,则设置为null
        // 此处设置了左侧搜索图标

        // 另外一个相似的方法:setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)介绍
        // 与 setCompoundDrawablesWithIntrinsicBounds()的区别:可设置图标大小
        // 传入的Drawable对象必须已经setBounds(x,y,width,height),即必须设置过初始位置、宽和高等信息
        // x:组件在容器X轴上的起点 y:组件在容器Y轴上的起点 组件的长度 height:组件的高度

    示例是给标签文本设置图标

    ....
    
    searchRecordsLabel.setLabels(searchRecordList, new LabelsView.LabelTextProvider<SearchWordBean>() {
                @Override
                public CharSequence getLabelText(TextView label, int position, SearchWordBean data) {
    
                    // return null;
    
                    // label就是标签项,在这里可以对标签项单独设置一些属性,比如文本样式等。
                    Drawable wordDrawable = getResources().getDrawable(R.drawable.main_ic_12_hot);
    
                    label.setCompoundDrawablesWithIntrinsicBounds(wordDrawable, null, null, null);
    
                    //根据data和position返回label需要显示的数据。
                    return data.getName();
                }
            });
            
    ....
    
    trendingRecordsLabel.setLabels(searchTrendingList, new LabelsView.LabelTextProvider<SearchWordBean>() {
                @Override
                public CharSequence getLabelText(TextView label, int position, SearchWordBean data) {
    
                    // return null;
    
                    // label就是标签项,在这里可以对标签项单独设置一些属性,比如文本样式等。
                    Drawable wordDrawable = getResources().getDrawable(R.drawable.main_ic_12_hot);
                    wordDrawable.setBounds(0, 0, wordDrawable.getMinimumWidth(), wordDrawable.getMinimumHeight());
    
                    label.setCompoundDrawables(wordDrawable, null, null, null);
    
                    //根据data和position返回label需要显示的数据。
                    return data.getName();
                }
            });
    ...
  • 相关阅读:
    LINQ 查询介绍
    HTML DOM all 集合
    JavaScript eval() 函数
    软件设计之 数据库设计
    Asp.Net下导出/导入规则的Excel(.xls)文档
    软件设计之 用户界面设计
    HTML DOM focus() 方法
    HTML DOM blur() 方法
    HTML DOM Event 对象
    控件用法参考:GridView的用法大全
  • 原文地址:https://www.cnblogs.com/heheisme/p/15541438.html
Copyright © 2020-2023  润新知