Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PageBarFragment: Fragment() {
- ...
- private val pageTextView: TextView get() = buildPageTextView()
- private fun buildPageTextView(): TextView {
- val pageTextView = TextView(context)
- pageTextView.setOnClickListener {
- currentPage = pageTextView.text.toString().toInt()
- changePage(currentPage)
- }
- val params = RelativeLayout.LayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.MATCH_PARENT)
- params.rightMargin = 8
- pageTextView.layoutParams = params
- pageTextView.textAlignment = View.TEXT_ALIGNMENT_CENTER
- pageTextView.textSize = 20.toFloat()
- val textColor = ContextCompat.getColor(requireContext(), R.color.colorText)
- pageTextView.setTextColor(textColor)
- return pageTextView
- }
- fun updatePageList() {
- binding.pageList.removeAllViewsInLayout()
- ...
- fun addPagesRange(start: Int, end: Int) {
- for (page in start..end) {
- val pageView = pageTextView
- pageView.text = page.toString()
- if (page == currentPage) {
- val accentColor = ContextCompat.getColor(requireContext(), R.color.colorLinkText)
- pageView.setTextColor(accentColor)
- }
- binding.pageList.addView(pageView)
- }
- }
- ...
- }
- <?xml version="1.0" encoding="utf-8"?>
- <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/colorPrimary">
- <LinearLayout
- android:id="@+id/page_list"
- android:layout_width="0dp"
- android:layout_height="30dp"
- android:layout_marginStart="8dp"
- android:layout_marginTop="8dp"
- android:layout_marginEnd="8dp"
- android:layout_marginBottom="8dp"
- android:orientation="horizontal"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toStartOf="@+id/next_page_button"
- app:layout_constraintHorizontal_bias="0.0"
- app:layout_constraintStart_toEndOf="@+id/prev_page_button"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="1.0" >
- </LinearLayout>
- <ImageView
- android:id="@+id/prev_page_button"
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginStart="8dp"
- android:layout_marginTop="8dp"
- android:layout_marginBottom="8dp"
- android:textAlignment="center"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="1.0"
- app:srcCompat="@drawable/ic_arrow_left" />
- <ImageView
- android:id="@+id/next_page_button"
- android:layout_width="30dp"
- android:layout_height="30dp"
- android:layout_marginTop="8dp"
- android:layout_marginEnd="8dp"
- android:layout_marginBottom="8dp"
- android:textAlignment="center"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="1.0"
- app:srcCompat="@drawable/ic_arrow_right" />
- <EditText
- android:id="@+id/page_number_field"
- android:layout_width="54dp"
- android:layout_height="32dp"
- android:layout_marginTop="8dp"
- android:layout_marginBottom="8dp"
- android:ems="10"
- android:inputType="number"
- app:layout_constraintBottom_toTopOf="@+id/page_list"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
- </androidx.constraintlayout.widget.ConstraintLayout>
Advertisement
Add Comment
Please, Sign In to add comment