TitleFragment.kt
package com.example.android.navigation
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.example.android.navigation.databinding.FragmentTitleBinding
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
/**
* A simple [Fragment] subclass.
* Use the [TitleFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class TitleFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
val binding = DataBindingUtil.inflate<FragmentTitleBinding>(inflater,
R.layout.fragment_title, container, false)
return binding.root
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2018, The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- TODO (04) Add a fragment tag for the titleFragment in the LinearLayout
Use @+id/titleFragment for the android:id
Use com.example.android.navigation.TitleFragment for the android:name
Use match_parent for the layout_height and layout_width -->
<fragment
android:id="@+id/titleFragment"
android:name="com.example.android.navigation.TitleFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</layout>
'안드로이드 Android > Android Study Jams' 카테고리의 다른 글
4. Navigation - Start an external activity (0) | 2021.01.07 |
---|---|
4. Navigation - Define navigation paths (0) | 2020.12.28 |
[Android Study Jams] Layouts (0) | 2020.12.18 |
[Android Study Jams] Build an interactive app (0) | 2020.12.18 |
[Android Study Jams] Build Your First App (0) | 2020.11.13 |