Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Androidアプリを作る 第5回

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for nonylene nonylene
December 13, 2016

Androidアプリを作る 第5回

Avatar for nonylene

nonylene

December 13, 2016
Tweet

More Decks by nonylene

Other Decks in Technology

Transcript

  1. * MainActivity.java public class MainActivity extends AppCompatActivity { @Override protected

    void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } "DUJWJUZ
  2. * MainActivity.java public class MainActivity extends AppCompatActivity { @Override protected

    void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } ىಈ͢Δ࣌ʹݺ͹ΕΔ ίϯετϥΫλͰ Activity ؔ࿈ͷॳظԽΛ͠Α͏ͱ͢Δͱ·ͩॳظԽ͕ࡁΜͰͳ͍͜ͱ͕͋Δ
  3. w onCreate()ىಈʢॳظԽॲཧʣ w onStart() ࢝·Δ w ྫىಈ͢ΔɾStopޙ·ͨલ໘ʹ໭ͬͨ w onStop()ࢭ·ͬͨ w

    ྫऴྃ͢Δɾଞͷ"DUJWJUZ͕લ໘ʹग़ͨ w onDestroy() ऴྃ͢Δʢޙย෇͚ʣ ϥΠϑαΠΫϧ
  4. * MainActivity.java public class MainActivity extends AppCompatActivity { @Override protected

    void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } ϨΠΞ΢τΛදࣔ R.layout.activity_main ʹؔͯ͠͸ޙड़
  5. * AndroidManifest.xml <?xml versi…?> <manifest package=“net.nonylene.myslack" …> <application …> <activity

    android:name=“.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest> "OESPJE.BOJGFTUYNM
  6. ໌ࣔత*OUFOU * MainActivity.java Intent intent = new Intent(this, Main2Activity.class); intent.putExtra("name",

    “nonylene"); startActivity(intent); .BJO"DUJWJUZΛىಈ this ͸ Context Ͱɺ͜͜Ͱ͸ MainActivity ࣗ਎ΛೖΕ͍ͯΔ. 
 (Activity ͸ Context ͷࢠΫϥε) Context ͸ΞϓϦͷ؀ڥ৘ใͳͲΛऔಘ͢Δͷʹ࢖ΘΕ͍ͯΔ.
  7. * MainActivity.java Intent intent = new Intent(this, Main2Activity.class); intent.putExtra("name", “nonylene");

    startActivity(intent); ໌ࣔత*OUFOU *OUFOUΛ౤͛Δ .BJO"DUJWJUZ͕ىಈ
  8. ҉໧త*OUFOU * MainActivity.java Uri uri = Uri.parse(“https://www.kmc.gr.jp/"); Intent intent =

    new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); 6SJΦϒδΣΫτΛ࡞੒
  9. ҉໧త*OUFOU * MainActivity.java Uri uri = Uri.parse(“https://www.kmc.gr.jp/"); Intent intent =

    new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); "$5*0/@7*&8ʢӾཡ͢Δʣͱ։͘6SJΛࢦఆ
  10. งғؾ * activity_main.xml <?xml version="1.0" encoding=“utf-8"?> <RelativeLayout android:id="@+id/activity_main" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="net.nonylene.myslack.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!"/> </RelativeLayout>
  11. งғؾ * activity_main.xml <?xml version="1.0" encoding=“utf-8"?> <RelativeLayout android:id="@+id/activity_main" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="net.nonylene.myslack.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!"/> </RelativeLayout> શମͷϨΠΞ΢τ
  12. งғؾ * activity_main.xml <?xml version="1.0" encoding=“utf-8"?> <RelativeLayout android:id="@+id/activity_main" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="net.nonylene.myslack.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!"/> </RelativeLayout> 5FYUදࣔ
  13. * MainActivity.java public class MainActivity extends AppCompatActivity { @Override protected

    void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } MBZPVUBDUJWJUZ@NBJOYNMΛදࣔ 3Ϋϥε
  14. QBEEJOHNBSHJO w ༨നΛઃఆ͢ΔͨΊͷଐੑ w શମ5PQ #PUUPN 4UBSU  &OE ͕ઃఆͰ͖Δ

    w ݹ͍୺຤Ͱ͸-FGU3JHIUʹͳΔ w ΞϥϏΞޠͳͲٯ޲͖ͷݴޠͰ΋ಉ͡ʹͳΔ
  15. 7JTJCJMJUZ • android:visibility • ཁૉͷදࣔɾඇදࣔઃఆ • VISIBLE: ݟ͑ΔʢσϑΥϧτʣ • INVISIBLE:

    ݟ͑ͳ͍͕εϖʔε͸औΔʢಁ໌ʣ • GONE: ݟ͑ͳ͍͠εϖʔε΋औΒͳ͍ʢফڈʣ
  16. MBZPVU@HSBWJUZ • android:layout_gravity w ਌ͷ7JFXʹରͯ͠Ͳͷ৔ॴʹஔ͔͘ • hoge|piyo ͷΑ͏ʹॎԣͷҐஔΛࢦఆ • top

    / bottom / start / end / center_horizontal / center_vertical • LinearLayout / FrameLayout ޙड़ Ͱ࢖͏
  17. ͍Ζ͍Ζͳଐੑ • android:text / textColor / textSize w จࣈྻɾจࣈ৭ɾจࣈαΠζΛࢦఆ •

    android:background w എܠͷ৭΍ը૾Λࢦఆ • android:hint w &EJU5FYUʹจࣈΛೖΕΔલͷώϯτΛઃఆ