Java Code Examples for android.widget.TextView.getBackground()

The following are Jave code examples for showing how to use getBackground() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: OSchina_resources_android   File: TeamIssueDetailFragment.java   Source Code and License Vote up 6 votes
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);
        }
    }
}
 
Example 2
Project: SScheduleView-Android   File: CustomSSViewAdapter.java   Source Code and License Vote up 6 votes
/**
     * 有课程的格子
     * @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;
    }
 
Example 3
Project: android-instant-apps   File: TextResize.java   Source Code and License Vote up 5 votes
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;
}
 
Example 4
Project: AssistantBySDK   File: RspMsgItemView.java   Source Code and License Vote up 5 votes
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();
}
 
Example 5
Project: XinFramework   File: CommonTitleBar.java   Source Code and License Vote up 5 votes
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);
        }
    }
}
 
Example 6
Project: XinFramework   File: TitleBar.java   Source Code and License Vote up 5 votes
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);
        }
    }
}
 
Example 7
Project: LoginConcept   File: TextSizeTransition.java   Source Code and License Vote up 5 votes
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;
}
 
Example 8
Project: Earthquake-report-app   File: EarthquakeAdapter.java   Source Code and License Vote up 4 votes
@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;
}
 
Example 9
Project: LeMondeRssReader   File: ArticleAdapter.java   Source Code and License Vote up 4 votes
@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;
    }
}
 
Example 10
Project: andriodapp   File: CustomAdapter.java   Source Code and License Vote up 2 votes
@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;


}