mirror of
https://github.com/Skysamara/android-kotlin-fundamentals-apps.git
synced 2025-12-05 22:06:04 +00:00
Android Kotlin Fundamentals 03.2: Define navigation paths
14. Homework. Add buttons
This commit is contained in:
parent
9e27afc707
commit
326d549cec
@ -22,6 +22,7 @@ import android.view.*
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.ui.NavigationUI
|
||||
import com.example.android.navigation.databinding.FragmentTitleBinding
|
||||
|
||||
@ -45,6 +46,14 @@ class TitleFragment : Fragment() {
|
||||
binding.playButton.setOnClickListener { view: View ->
|
||||
view.findNavController().navigate(R.id.action_titleFragment_to_gameFragment)
|
||||
}
|
||||
binding.rulesButton.setOnClickListener { view ->
|
||||
view.findNavController().navigate(R.id.action_titleFragment_to_rulesFragment)
|
||||
}
|
||||
|
||||
binding.aboutButton.setOnClickListener {
|
||||
findNavController().navigate(R.id.action_titleFragment_to_aboutFragment)
|
||||
}
|
||||
|
||||
setHasOptionsMenu(true)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@ -26,36 +26,60 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/titleImage"
|
||||
android:layout_width="395dp"
|
||||
android:layout_height="@dimen/image_header_height"
|
||||
android:scaleType="fitCenter"
|
||||
app:layout_constraintBottom_toTopOf="@+id/playButton"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/android_trivia"
|
||||
tools:layout_editor_absoluteX="8dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/playButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/horizontal_margin"
|
||||
android:layout_marginEnd="@dimen/horizontal_margin"
|
||||
android:paddingStart="@dimen/button_padding"
|
||||
android:paddingEnd="@dimen/button_padding"
|
||||
android:text="Play"
|
||||
android:textColor="@color/colorAccent"
|
||||
android:textSize="@dimen/button_text_size"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@+id/rulesButton"
|
||||
app:layout_constraintEnd_toEndOf="@+id/titleImage"
|
||||
app:layout_constraintStart_toStartOf="@+id/titleImage"
|
||||
app:layout_constraintTop_toBottomOf="@+id/titleImage" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/titleImage"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/image_header_height"
|
||||
android:layout_marginStart="@dimen/horizontal_margin"
|
||||
android:layout_marginEnd="@dimen/horizontal_margin"
|
||||
android:scaleType="fitCenter"
|
||||
app:layout_constraintBottom_toTopOf="@+id/playButton"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/android_trivia" />
|
||||
<Button
|
||||
android:id="@+id/rulesButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="@dimen/button_padding"
|
||||
android:paddingEnd="@dimen/button_padding"
|
||||
android:text="Rules"
|
||||
android:textColor="@color/colorAccent"
|
||||
android:textSize="@dimen/button_text_size"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@+id/aboutButton"
|
||||
app:layout_constraintEnd_toEndOf="@+id/playButton"
|
||||
app:layout_constraintStart_toStartOf="@+id/playButton"
|
||||
app:layout_constraintTop_toBottomOf="@+id/playButton" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/aboutButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="@dimen/button_padding"
|
||||
android:paddingEnd="@dimen/button_padding"
|
||||
android:text="About"
|
||||
android:textColor="@color/colorAccent"
|
||||
android:textSize="@dimen/button_text_size"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="@+id/rulesButton"
|
||||
app:layout_constraintStart_toStartOf="@+id/rulesButton"
|
||||
app:layout_constraintTop_toBottomOf="@+id/rulesButton" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
@ -13,6 +13,12 @@
|
||||
<action
|
||||
android:id="@+id/action_titleFragment_to_gameFragment"
|
||||
app:destination="@id/gameFragment" />
|
||||
<action
|
||||
android:id="@+id/action_titleFragment_to_rulesFragment"
|
||||
app:destination="@id/rulesFragment" />
|
||||
<action
|
||||
android:id="@+id/action_titleFragment_to_aboutFragment"
|
||||
app:destination="@id/aboutFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/gameFragment"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user