Background color to spanableString in android

后端 未结 2 732
遇见更好的自我
遇见更好的自我 2021-01-13 02:43

I am using only one text view and using spanable to add fonts and color to strings. But i am getting problem to display rounded background to string using spanable. So How c

2条回答
  •  既然无缘
    2021-01-13 02:56

    I have achieved the above UI like this.. Created Horizontal scroll-view and one Linear Layout with horizontal orientation. next during run-time depending upon the No of Strings in array i have added text view in Linear Layout that's it. The code is as below.

        private void addTextView(ArrayList list,String whichLayout){
    
        for (int i = 0; i < list.size(); i++) {
             TextView textView = new TextView(getActivity());
             Spannable spValue = new SpannableString(list.get(i).toString());
             textView.setText(customeSpan.getRequiredFontTypeToText(spValue, tfHintTxtValue));
             textView.setTextSize(12.0f);
             textView.setTextColor(getResources().getColor(R.color.black));
             textView.setBackgroundResource(R.drawable.red_solid_background);
             LinearLayout.LayoutParams lllp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
             lllp.setMargins(0, 2, 10, 0); // llp.setMargins(left, top, right, bottom);
             textView.setLayoutParams(lllp);
             if(whichLayout.equalsIgnoreCase("hieghtWieght")){
                 ((LinearLayout) heightWieghtLinearLayout).addView(textView);
             }else if(whichLayout.equalsIgnoreCase("bodyType")){
                 ((LinearLayout) bodyTypeLinearLayout).addView(textView);
             }else if(whichLayout.equalsIgnoreCase("eyeHair")){
                 ((LinearLayout) eyeHairColorLinearLayout).addView(textView);
             }else if(whichLayout.equalsIgnoreCase("bestFeatures")){
                 ((LinearLayout) bestFeaturesLinearLayout).addView(textView);
             }else if(whichLayout.equalsIgnoreCase("personalStyle")){
                 ((LinearLayout) personalStyleLinearLayout).addView(textView);
             }else if(whichLayout.equalsIgnoreCase("zodiacSign")){
                 ((LinearLayout) zodizcSignLinearLayout).addView(textView);
             }else if(whichLayout.equalsIgnoreCase("personalityTraits")){
                 ((LinearLayout) personalityLinearLayout).addView(textView);
             }  
        }
    } 
    

提交回复
热议问题