본문 바로가기
End/#10 모여라 미대생

#5 모여라 미대생 - Custom Dialog, 카메라, 앨범[안드로이드 앱 개발]

by 퍼즐잎 2017. 6. 23.



게시판에 글을 작성하는 기능 중 이미지를 업로드하는 기능이 있다.

이미지는 카메라 촬영을 통해서 가지고 오는 방법과 앨범, 갤러리에서 가져오는 방법이 있다.


두 가지 방법을 안내 해주기 위헤서 Dialog를 Custom 해서 만들 수 있는데

다음과 같이 쉽게 배경이 투명한 Dialog를 만들 수 있다.


TextView는 커스텀 한거라서 기존의 TextView로 변경해서 사용하면 된다.







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
//CameraDialog.java
public class CameraDialog extends Dialog {
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.board_camera_dialog);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
 
    }
 
    public CameraDialog(Context context) {
        super(context,R.style.theme_dialog);
    }
}
 
cs



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
45
46
47
48
49
50
51
//board_camera_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/camera_dialog"
    android:background="#96000000"
    android:gravity="bottom|center"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_marginBottom="15dp"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:tint="#ffffff"
            android:adjustViewBounds="true"
            android:src="@drawable/camera" />
        <com.crossit.collegeoffinearts.Tab.board.FontTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="15sp"
            android:textColor="#ffffff"
            android:layout_marginLeft="8dp"
            android:text="카메라로 사진찍기"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_marginBottom="70dp"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:tint="#ffffff"
            android:adjustViewBounds="true"
            android:src="@drawable/gallery" />
        <com.crossit.collegeoffinearts.Tab.board.FontTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:textColor="#ffffff"
            android:textSize="15sp"
            android:text="앨범에서 사진선택"/>
    </LinearLayout>
</LinearLayout>
cs



1
2
3
4
5
6
7
8
9
10
11
12
//사용법
private CameraDialog cameraDialog;
cameraDialog = new CameraDialog(getContext());
cameraDialog.show();
 
//style
    <style name="theme_dialog" parent="android:style/Theme.Dialog">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:background">@android:color/transparent</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>
cs


댓글