1 / 21

Tworzenie aplikacji mobilnych

Tworzenie aplikacji mobilnych. Android. Widgety. Widget = kontrolka Dziedziczą od klasy View. <? xml version= "1.0" encoding ="utf-8"?> < LinearLayout xmlns:android = "http://schemas.android.com/ apk /res/android" android:orientation = " vertical "

Télécharger la présentation

Tworzenie aplikacji mobilnych

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tworzenie aplikacji mobilnych Android

  2. Widgety • Widget = kontrolka • Dziedziczą od klasy View

  3. <?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>

  4. Przycisk <Button xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/button" android:text="" android:layout_width="fill_parent" android:layout_height="fill_parent"/>

  5. Identyfikator obiektu • android:id="@+id/button" • android:text="@string/hello"

  6. Inicjalizacja @Override public voidonCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); btn=(Button)findViewById(R.id.button); btn.setOnClickListener(this); updateTime(); }

  7. Przypisanie zdarzenia w xml <Button android:onClick="someMethod" ... /> W pliku .java public voidsomeMethod(ViewtheButton) { // kod funkcji }

  8. TextView <TextViewxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Textwyswietlany przez obiekt TextView" />

  9. Inne atrybuty dla TextView • android:typeface: ustawia typeface etykiety (np.,monospace) • android:textStyle: Styl textu pogrubienie (bold), pochylenie (italic), lub pogurbione i pochylone (bold_italic) • android:textColor: Ustawiw kolor textu w formacie RGB (np., #FF0000 - czerwony)

  10. ImageView, ImageButton <ImageViewxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/icon" android:layout_width="fill_parent" android:layout_height="fill_parent" android:adjustViewBounds="true" android:src="@drawable/molecule" />

  11. EditText • android:autoText:Ustawia automatyczną kontrolę poprawności pisania • android:capitalize:Ustawienie pisania pierwszej litery jako Kapitalika • android:digits: Ustawia pole w tryb liczbowy (akceptuje tylko liczby) • android:singleLine:Ustwienie trybu pojedynczej linii tekstu (true/false)

  12. EditText <EditTextxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/field" android:layout_width="fill_parent" android:layout_height="fill_parent" android:singleLine="false" /> public class FieldDemo extends Activity { @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); EditTextfld=(EditText)findViewById(R.id.field);\ fld.setText("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"); } }

  13. CheckBox • <?xml version="1.0" encoding="utf-8"?> • <CheckBoxxmlns:android="http://schemas.android.com/apk/res/android" • android:id="@+id/check" • android:layout_width="wrap_content" • android:layout_height="wrap_content" • android:text="Tencheckbox jest niezaznaczony" />

  14. CheckBoxObsluga zdarzeń public class CheckBoxDemo extends Activity implementsCompoundButton.OnCheckedChangeListener { CheckBoxcb; @Override public voidonCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); cb=(CheckBox)findViewById(R.id.check); cb.setOnCheckedChangeListener(this); } public voidonCheckedChanged(CompoundButtonbuttonView, booleanisChecked) { if(isChecked) { cb.setText("This checkbox is: checked"); } else{ cb.setText("This checkbox is: unchecked"); } } }

  15. RadioButton, RadioGroup • check(): Sprawdza wybrany radio button z wykorzystaniem jego id (np. group.check(R.id.radio1)) • clearCheck(): „czyści” wszystkie radiobuttony w grupie • getCheckedRadioButtonId(): Pobiera id zaznaczonego radio buttona (-1 jeśli żaden nie został wybrany)

  16. <?xml version="1.0" encoding="utf-8"?> <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <RadioButtonandroid:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Rock" /> <RadioButtonandroid:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Scissors" /> <RadioButtonandroid:id="@+id/radio3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Paper" /> </RadioGroup>

  17. Inne właściwości widgetów • android: visibility: Kontroluje widoczność widgetu • android:nextFocusDown, android:nextFocusLeft, • android:nextFocusRight, android:nextFocusUp: Kontrilują kolejność uzyskiwania fokusa w przypadku użycia D-Pada, trackaball itp. • android:contentDescription: Może być wykorzystywane przez narzędzia dla osób niewidomych odpowiednik atrybutu alt w znaczniki <img> w html

  18. Metody Widgetów • setEnabled(), isEnabled() • requestFocus(), isFocused()

  19. Nawigacja po drzewie widgetów • getParent(): Odnajduje rodzica widgetu lub kontener w którym się on znajduje • findViewById(): Znajduje widget potomny (umieszczony w danym kotenerze) dla zadanego ID • getRootView(): Znajduje główny kontener całego activity ustawiony przez setContentView()

More Related