-1

This is sample code, i need to change text color in text view for certain condition. like, for different months text color should different . Thank you.

FragmentOne.kt

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup



class FragmentOne : Fragment() {



    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_one, container, false)

    }

}

fragment_one.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".FragmentOne">


    <TextView
        android:id="@+id/textview"
        android:textAlignment="center"
        android:layout_gravity="center"
        android:background="#7654ad"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="me !" />

</FrameLayout>
P. Mohanta
  • 130
  • 2
  • 15

1 Answers1

0

Can you try this inside onCreateView method

var view = inflater.inflate(R.layout.fragment1, container, false);
var textView : TextView = view?.findViewById(R.id.textview) as TextView
//your condition,then set the color. Use if or when
textView.setTextColor(Color.RED)
George Isaac
  • 569
  • 4
  • 9