NewPaymentActivity
class NewPaymentActivity : AppCompatActivity(),SummaryFragment.OnFragmentInteractionListener{
override fun onFragmentInteraction(uri: Uri) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
internal lateinit var viewpageradapter: ViewPagerAdapter //Declare PagerAdapter
private var tabLayout: TabLayout? = null
var viewPager: ViewPager? = null
var toolbar: Toolbar? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_new_payment)
viewpageradapter= ViewPagerAdapter(supportFragmentManager)
viewPager = findViewById(R.id.viewPager) as ViewPager
setupViewPager(viewPager!!)
tabLayout = findViewById(R.id.tab_layout) as TabLayout
tabLayout!!.setupWithViewPager(viewPager)
tabLayout!!.setSelectedTabIndicatorColor(getResources().getColor(R.color.main));
val headerView = (getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater)
.inflate(R.layout.custom_tabs_for_payments, null, false)
val receiptDetails = headerView.findViewById(R.id.tb_receipt_details) as TextView
val paymentDetails = headerView.findViewById(R.id.tb_payment_details) as TextView
val invoiceDetails = headerView.findViewById(R.id.tb_invoice_details) as TextView
val summary = headerView.findViewById(R.id.tb_summary) as TextView
tabLayout!!.getTabAt(0)!!.setCustomView(receiptDetails)
tabLayout!!.getTabAt(1)!!.setCustomView(paymentDetails)
tabLayout!!.getTabAt(2)!!.setCustomView(invoiceDetails)
tabLayout!!.getTabAt(3)!!.setCustomView(summary)
}
private fun setupViewPager(viewPager: ViewPager) {
val adapter = ViewPagerAdapter(supportFragmentManager)
adapter.addFragment(ReceiptDetailsFragment(), "Receipt Details")
adapter.addFragment(PaymentDetailsFragment(), "Payment Details")
adapter.addFragment(InvoiceDetailsFragment(), "Invoice Details")
adapter.addFragment(SummaryFragment(), "Summary")
viewPager.adapter = adapter
}
internal inner class ViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
private val mFragmentList = ArrayList<Fragment>()
private val mFragmentTitleList = ArrayList<String>()
override fun getItem(position: Int): Fragment {
return mFragmentList[position]
}
override fun getCount(): Int {
return mFragmentList.size
}
fun addFragment(fragment: Fragment, title: String) {
mFragmentList.add(fragment)
mFragmentTitleList.add(title)
}
override fun getPageTitle(position: Int): CharSequence {
return mFragmentTitleList[position]
}
}
}
custom_tabs_for_payment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:layout_margin="@dimen/dimen_6dp"
android:background="@color/row_gray"
android:orientation="horizontal">
<TextView
android:id="@+id/tb_receipt_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/left_tab"
android:gravity="center"
android:paddingBottom="@dimen/dimen_10dp"
android:paddingStart="@dimen/dimen_6dp"
android:paddingTop="@dimen/dimen_10dp"
android:text="Receip tDetails"
android:textColor="@color/main"
android:textSize="@dimen/text_dimen_8sp" />
<TextView
android:id="@+id/tb_payment_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/first_middle_tab"
android:layout_weight="1"
android:gravity="center"
android:paddingBottom="@dimen/dimen_10dp"
android:paddingStart="@dimen/dimen_6dp"
android:paddingTop="@dimen/dimen_10dp"
android:text="Payment Details"
android:textColor="@color/main"
android:textSize="@dimen/text_dimen_8sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tb_invoice_details"
android:layout_weight="1"
android:background="@drawable/second_middle_tab"
android:gravity="center"
android:paddingBottom="@dimen/dimen_10dp"
android:paddingStart="@dimen/dimen_6dp"
android:paddingTop="@dimen/dimen_10dp"
android:text="Invoice Details"
android:textColor="@color/main"
android:textSize="@dimen/text_dimen_8sp" />
<TextView
android:id="@+id/tb_summary"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/right_tab"
android:gravity="center"
android:paddingBottom="@dimen/dimen_10dp"
android:paddingRight="@dimen/dimen_6dp"
android:paddingStart="@dimen/dimen_6dp"
android:paddingTop="@dimen/dimen_10dp"
android:text="Summary"
android:textColor="@color/main"
android:textSize="@dimen/text_dimen_8sp" />
</LinearLayout>
Мне нужно изменить текущее представление текста макета вкладкив зависимости от выбора. Есть способ изменить выбранный цвет вкладки, но мне нужно получить доступ к пользовательскому виду и изменить цвета текста и фон текста. Ниже я добавил текущий экран. Я новичок в Kotlin. Спасибо заранее.