Kotlin for Android Developers


 Creating the settings activity



Download 1,04 Mb.
Pdf ko'rish
bet114/125
Sana11.08.2021
Hajmi1,04 Mb.
#144654
1   ...   110   111   112   113   114   115   116   117   ...   125
Bog'liq
Kotlin for Android Developers Learn Kotlin the Easy Way While Developing an Android App ( PDFDrive )


2
#ff212121
3
@android:color/black
4
26.1 Creating the settings activity
A new activity will we opened when the settings option is selected in the overflow menu in the
toolbar. So first thing we need is a new
SettingsActivity
:
1
class SettingsActivity : AppCompatActivity() {
2
3
override fun onCreate(savedInstanceState: Bundle?) {
4
super.onCreate(savedInstanceState)
5
setContentView(R.layout.activity_settings)
6
setSupportActionBar(toolbar)
7
supportActionBar?.setDisplayHomeAsUpEnabled(true)
8
}
9
10
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
11
android.R.id.home -> { onBackPressed(); true }
12
else -> false
13
}
14
}
We’ll save the preference when the user gets out of the screen activity, so we’re going to deal with
the
Up
action the same way as the
Back
one, by redirecting the action to
onBackPressed
. By now,
let’s create the XML layout. A simple
EditText
will be enough for the preference:
126


26 Settings Screen
127
1
2
xmlns:android="http://schemas.android.com/apk/res/android"
3
android:layout_width="match_parent"
4
android:layout_height="match_parent">
5
6

7
8
9
android:orientation="vertical"
10
android:layout_width="match_parent"
11
android:layout_height="match_parent"
12
android:layout_marginTop="?attr/actionBarSize"
13
android:padding="@dimen/spacing_xlarge">
14
15
16
android:layout_width="wrap_content"
17
android:layout_height="wrap_content"
18
android:text="@string/city_zipcode"/>
19
20
21
android:id="@+id/cityCode"
22
android:layout_width="match_parent"
23
android:layout_height="wrap_content"
24
android:hint="@string/city_zipcode"
25
android:inputType="number"/>
26
27

28
29

And then just declare the activity in the
AndroidManifest.xml
:
1
2
android:name=".ui.activities.SettingsActivity"
3
android:label="@string/settings"/>

Download 1,04 Mb.

Do'stlaringiz bilan baham:
1   ...   110   111   112   113   114   115   116   117   ...   125




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish