当前位置: 首页>>代码示例>>Java>>正文


Java TextView.getBackground方法代码示例

本文整理汇总了Java中android.widget.TextView.getBackground方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.getBackground方法的具体用法?Java TextView.getBackground怎么用?Java TextView.getBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.TextView的用法示例。


在下文中一共展示了TextView.getBackground方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setLabels

import android.widget.TextView; //导入方法依赖的package包/类
private void setLabels(TeamIssue issue) {
    if (issue.getLabels() == null || issue.getLabels().isEmpty()) {
        mLLlabels.setVisibility(View.GONE);
    } else {
        for (TeamIssue.Label label : issue.getLabels()) {
            TextView text = (TextView) LayoutInflater.from(getActivity())
                    .inflate(R.layout.team_issue_lable, null, false);
            text.setText(label.getName());
            String colorStr = label.getColor();
            if (colorStr.equalsIgnoreCase("#ffffff")) {
                colorStr = "#000000";
            }
            int color = Color.parseColor(colorStr);
            LayoutParams params = new LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            params.setMargins(4, 0, 4, 0);

            GradientDrawable d = (GradientDrawable) text.getBackground();
            d.setStroke(1, color);
            text.setTextColor(color);

            mLLlabels.addView(text, params);
        }
    }
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:26,代码来源:TeamIssueDetailFragment.java

示例2: getCourseView

import android.widget.TextView; //导入方法依赖的package包/类
/**
     * 有课程的格子
     * @return
     */
    public TextView getCourseView(SScheduleViewModelInterface data) {
        TextView couseInfoTV = new TextView(mContext);
        couseInfoTV.setText(data.getCourseName() + "\n" + data.getClassRoom());
        couseInfoTV.setTextColor(Color.WHITE);
        couseInfoTV.setGravity(Gravity.CENTER);
//        couseInfoTV.setPadding(oneW, oneW, oneW, oneW);
        couseInfoTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
        couseInfoTV.setEllipsize(TextUtils.TruncateAt.END);
        couseInfoTV.setLines(7);

        // 设置背景颜色
        int bg = new Random().nextInt(SScheduleTheme.COURSE_BG.length - 1);
        couseInfoTV.setBackgroundResource(SScheduleTheme.COURSE_BG[bg]);
        if (data.getBackColor() != 0) {
            GradientDrawable myGrad = (GradientDrawable) couseInfoTV.getBackground();
            myGrad.setColor(data.getBackColor());
        }

        return couseInfoTV;
    }
 
开发者ID:huangshuai-IOT,项目名称:SScheduleView-Android,代码行数:25,代码来源:CustomSSViewAdapter.java

示例3: captureTextBitmap

import android.widget.TextView; //导入方法依赖的package包/类
private static Bitmap captureTextBitmap(TextView textView) {
    Drawable background = textView.getBackground();
    textView.setBackground(null);
    int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
    int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
    if (width == 0 || height == 0) {
        return null;
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
    textView.draw(canvas);
    textView.setBackground(background);
    return bitmap;
}
 
开发者ID:googlesamples,项目名称:android-instant-apps,代码行数:16,代码来源:TextResize.java

示例4: init

import android.widget.TextView; //导入方法依赖的package包/类
protected void init(Context mContext) {
    LayoutInflater iflater = LayoutInflater.from(mContext);
    iflater.inflate(R.layout.common_bubble_dialog_left, this);
    mTextView = (TextView) findViewById(R.id.common_bubble_left_text);
    mTextView.setOnTouchListener(this);
    mListDrawable = (LevelListDrawable) mTextView.getBackground();
}
 
开发者ID:LingjuAI,项目名称:AssistantBySDK,代码行数:8,代码来源:RspMsgItemView.java

示例5: setTextViewColor

import android.widget.TextView; //导入方法依赖的package包/类
private void setTextViewColor(TextView view, int color) {
    if (color == ORIGIN_COLOR) {
        view.setTextColor(mOriginBarTitleColor);
        if (view.getBackground() != null) {
            view.getBackground().clearColorFilter();
        }
    } else {
        view.setTextColor(color);
        if (view.getBackground() != null) {
            view.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        }
    }
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:14,代码来源:CommonTitleBar.java

示例6: setViewColor

import android.widget.TextView; //导入方法依赖的package包/类
private void setViewColor(TextView view, int color) {
    if (color == ORIGIN_COLOR) {
        view.setTextColor(mOriginBarTitleColor);
        if (view.getBackground() != null) {
            view.getBackground().clearColorFilter();
        }
    } else {
        view.setTextColor(color);
        if (view.getBackground() != null) {
            view.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        }
    }
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:14,代码来源:TitleBar.java

示例7: getView

import android.widget.TextView; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    //create a view
    View listItemView=convertView;
    //check for existing view,otherwise inflate a new layout
    if(listItemView==null){
        listItemView= LayoutInflater.from(getContext()).inflate(R.layout.earthquake_list_item,parent,false);
    }
    //find the earthquake at the given position in the list
    Earthquake currentEarthquake=getItem(position);




    //calling format method
    String magnitude=formatMagnitude(currentEarthquake.getmMagnitude());
    //find textView with id magnitude
    TextView magnitudeView=(TextView) listItemView.findViewById(R.id.magnitude);
    //Display the magnitude of current earthquake in that textView
    magnitudeView.setText(magnitude);

    //setting color of circle for magnitude
    // Set the proper background color on the magnitude circle.
    // Fetch the background from the TextView, which is a GradientDrawable.
    GradientDrawable magnitudeCircle = (GradientDrawable) magnitudeView.getBackground();

    // Get the appropriate background color based on the current earthquake magnitude
    int magnitudeColor = getMagnitudeColor(currentEarthquake.getmMagnitude());

    // Set the color on the magnitude circle
    magnitudeCircle.setColor(magnitudeColor);

    String originalLocation = currentEarthquake.getmLocation();
    String primaryLocation;
    String locationOffset;

    if (originalLocation.contains(LOCATION_SEPARATOR)) {
        String[] parts = originalLocation.split(LOCATION_SEPARATOR);
        locationOffset = parts[0] + LOCATION_SEPARATOR;
        primaryLocation = parts[1];
    } else {
        locationOffset = getContext().getString(R.string.near_the);
        primaryLocation = originalLocation;
    }


    TextView primaryLocationView = (TextView) listItemView.findViewById(R.id.primary_location);
    primaryLocationView.setText(primaryLocation);

    TextView locationOffsetView = (TextView) listItemView.findViewById(R.id.location_offset);
    locationOffsetView.setText(locationOffset);


    // Create a new Date object from the time in milliseconds of the earthquake
    Date dateObject = new Date(currentEarthquake.getmDate());
    // Find the TextView with view ID date
    TextView dateView = (TextView) listItemView.findViewById(R.id.date);
    // Format the date string (i.e. "Mar 3, 1984")
    String formattedDate = formatDate(dateObject);
    // Display the date of the current earthquake in that TextView
    dateView.setText(formattedDate);

    // Find the TextView with view ID time
    TextView timeView = (TextView) listItemView.findViewById(R.id.time);
    // Format the time string (i.e. "4:30PM")
    String formattedTime = formatTime(dateObject);
    // Display the time of the current earthquake in that TextView
    timeView.setText(formattedTime);

    //return the listItemView set with appropriate date
    return listItemView;
}
 
开发者ID:akspan12,项目名称:Earthquake-report-app,代码行数:73,代码来源:EarthquakeAdapter.java

示例8: onBindViewHolder

import android.widget.TextView; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {

    Model model = items.get(position);
    if (model == null) {
        return;
    }
    RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    RecyclerView.LayoutParams lp2 = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    switch (model.getType()) {
        case Model.TEXT_TYPE:
        case Model.COMMENT_TYPE:
            TextView textView = (TextView) model.getTheContent();
            ((ViewHolderText) holder).text.setText(textView.getText());
            ((ViewHolderText) holder).text.setPadding(textView.getPaddingLeft(), textView.getPaddingTop(), textView.getPaddingRight(), textView.getPaddingBottom());
            ((ViewHolderText) holder).text.setTypeface(textView.getTypeface());
            ((ViewHolderText) holder).text.setTextColor(textView.getCurrentTextColor());
            if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
                ((ViewHolderText) holder).text.setBackground(textView.getBackground());
            }
            if (textView.getBackground() != null) {
                ((ViewHolderText) holder).text.setAllCaps(true);
            }
            // Tag doesn't expand horizontally to the max
            if (textView.getLayoutParams() != null) {
                ((ViewHolderText) holder).text.setLayoutParams(textView.getLayoutParams());
            } else {
                ((ViewHolderText) holder).text.setLayoutParams(lp);
            }
            ((ViewHolderText) holder).text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getTextSize());
            break;
        case Model.IMAGE_TYPE:
            String imageURI = (String) model.getTheContent();
            ((ViewHolderImage) holder).image.setLayoutParams(lp);
            Picasso.with(((ViewHolderImage) holder).image.getContext()).load(imageURI).into(((ViewHolderImage) holder).image);
            break;
        case Model.TWEET_TYPE:
            CardView cardView = (CardView) model.getTheContent();
            TextView tweet = (TextView) cardView.getChildAt(0);
            Button link = (Button) cardView.getChildAt(1);
            ((ViewHolderTweet) holder).getTweet().setText(tweet.getText());
            ((ViewHolderTweet) holder).getLink().setContentDescription(link.getContentDescription());
            break;
        case Model.GRAPH_TYPE_BARS:
            Chart chart1 = (Chart) model.getTheContent();
            ((ViewHolderChart) holder).chart.setData(chart1.getData());
            ((ViewHolderChart) holder).chart.setLayoutParams(lp2);
            break;
        case Model.GRAPH_TYPE_COLUMNS:
            Chart chart2 = (Chart) model.getTheContent();
            ((ViewHolderChart) holder).chart.setData(chart2.getData());
            ((ViewHolderChart) holder).chart.setLayoutParams(lp2);
            break;
    }
}
 
开发者ID:MBach,项目名称:LeMondeRssReader,代码行数:57,代码来源:ArticleAdapter.java

示例9: getView

import android.widget.TextView; //导入方法依赖的package包/类
@NonNull
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View listItemView = convertView;

        if (listItemView == null) {

            listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
        }


        DATA k = getItem(position);
        String originalLocation = k.getMquakeplace();
        String primaryLocation;
        String locationOffset;
        if (originalLocation.contains(LOCATION_SEPAROTOR)) {

            String parts[] = originalLocation.split(LOCATION_SEPAROTOR);
            locationOffset = parts[0] + LOCATION_SEPAROTOR;
            primaryLocation = parts[1];
        } else
            {

            locationOffset = getContext().getString(R.string.near_the);
            primaryLocation = originalLocation;

        }

        DecimalFormat format = new DecimalFormat("0.00");

        String mag = format.format(k.getMquakemag());

        TextView textView = (TextView) listItemView.findViewById(R.id.quakemag);

        textView.setText("" + mag);
        GradientDrawable magnitudeCircle = (GradientDrawable) textView.getBackground();
        int magnitudeColor=getMagnitudeColor(k.getMquakemag());
        magnitudeCircle.setColor(magnitudeColor);

        TextView placetextView =(TextView) listItemView.findViewById(R.id.quakeplace);
        placetextView.setText("" + primaryLocation);


        TextView placetextView1=(TextView) listItemView.findViewById(R.id.quakeplace1);
        placetextView1.setText("" + locationOffset);


        TextView datetextView = (TextView) listItemView.findViewById(R.id.quakedate);
        Date dateObject = new Date(k.getMquakedate());
        SimpleDateFormat dateFormat = new SimpleDateFormat("LLL dd, yyyy");
        dateFormat.format(dateObject);

        datetextView.setText("" + dateFormat.format(dateObject));

        TextView timeview = (TextView) listItemView.findViewById(R.id.quaketime);
        Date datetime = new Date(k.getMquakedate());
        SimpleDateFormat dateFormat1 = new SimpleDateFormat("h:mm a");
        dateFormat1.format(datetime);

        timeview.setText("" + dateFormat1.format(datetime));


        return listItemView;


}
 
开发者ID:raghu619,项目名称:andriodapp,代码行数:68,代码来源:CustomAdapter.java


注:本文中的android.widget.TextView.getBackground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。