티스토리 뷰

액션바란?

상단에 위치하면서 여러가지 기능을 구현할수 있는 바

 

액션바의 기능

 

1. 애플리케이션과 사용자의 현재 위치를 식별

2. 각종 메뉴 - 탐색 메뉴, 액션 항목을 통한 단축 메뉴

3. 애플리케이션 사이의 내비게이션 지원 (탭이나 드롭다운 리스트)

 

액션바의 출력 옵션 상수

 

 

상단 액션바에서 버튼 두개 (흰바탕 ,검은 바탕)이

아주 적절하게 배치된 모습이다.

 

 

버튼 (검은바탕)을 클릭해서 출력한 모습입니다.

 

 

 

소스코드(ActionbarActivity4)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.example.a34354.testapp;
 
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
 
public class ActionbarActivity4 extends AppCompatActivity {
        View myButtonLayout;
        Button btnWhite;
        Button btnBlack;
        LinearLayout body;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_actionbar4);
        myButtonLayout = getLayoutInflater().inflate(R.layout.button,null);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setCustomView(myButtonLayout);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
        |ActionBar.DISPLAY_SHOW_TITLE|ActionBar.DISPLAY_SHOW_CUSTOM);
        btnWhite=(Button)myButtonLayout.findViewById((R.id.btnWhite));
        btnBlack = (Button)myButtonLayout.findViewById(R.id.btnBlack);
        body = (LinearLayout)findViewById(R.id.body);
 
        btnWhite.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                body.setBackgroundColor(Color.WHITE);
 
            }
        });
        btnBlack.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                body.setBackgroundColor(Color.BLACK);
 
            }
        });
    }
}
 

소스코드(button.xml)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
 
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="흰 바탕"
        android:id="@+id/btnWhite"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnBlack"
        android:text="검은 바탕"/>
 
 
</LinearLayout>

소스코드(activity_actionbar4.xml)

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/body"
    tools:context="com.example.a34354.testapp.ActionbarActivity4">
 
</LinearLayout>
 

 

 

 

 

 

 

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31