거의 전체 화면 DialogFragment를 표시하려고합니다. 그러나 나는 어떻게 든 그렇게 할 수 없습니다.
내가 조각을 보여주는 방식은 안드로이드 개발자 문서에서 나온 것입니다.
FragmentManager f = ((Activity)getContext()).getFragmentManager();
FragmentTransaction ft = f.beginTransaction();
Fragment prev = f.findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
// Create and show the dialog.
DialogFragment newFragment = new DetailsDialogFragment();
newFragment.show(ft, "dialog");
조각의 RelativeLayout을 fill_parent 및 minWidth 및 minHeight로 설정하려고 순진하게 시도했습니다.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="1000px"
android:minHeight="600px"
android:background="#ff0000">
DialogFragment가 화면의 대부분을 채울 것으로 예상합니다. 그러나 세로로만 크기를 조정하지만 가로로 고정 너비가 될 때까지만 크기를 조정합니다.
또한 http://groups.google.com/group/android-developers/browse_thread/thread/f0bb813f643604ec에서 제안한 것처럼 코드에서 창 속성을 설정하려고했습니다 . 그러나 이것은 도움이되지 않았습니다.
나는 안드로이드가 Dialogs를 어떻게 다루는 지에 대해 오해하고있을 것입니다. 이런 식으로 어떻게 할 수 있습니까? 목표를 달성 할 수있는 다른 방법이 있습니까?
안드로이드 장치 :
Asus EeePad Transformer
Android 3.0.1
업데이트 :
이제 조각에 다음 코드를 사용하여 전체 화면으로 가져 왔습니다.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Holo_Light);
}
불행히도, 이것은 내가 원하는 것이 아닙니다. 대화 상자 주변에 작은 “패딩”이 있어야 배경을 표시 할 수 있습니다.
그것을 달성하는 방법에 대한 아이디어가 있습니까?
답변
LinearLayout
대신로 전환 해보십시오 RelativeLayout
. 테스트 할 때 3.0 Honeycomb API를 타겟팅하고있었습니다.
public class FragmentDialog extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.show);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog();
}
});
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
void showDialog() {
FragmentTransaction ft = getFragmentManager().beginTransaction();
DialogFragment newFragment = MyDialogFragment.newInstance();
newFragment.show(ft, "dialog");
}
public static class MyDialogFragment extends DialogFragment {
static MyDialogFragment newInstance() {
MyDialogFragment f = new MyDialogFragment();
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_dialog, container, false);
return v;
}
}
}
및 레이아웃 :
fragment_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="1000dp"
android:minHeight="1000dp">
</LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<Button android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="show">
</Button>
</LinearLayout>
답변
전체 화면에서 DialogFragment를 가져 오려면
onStart
다음과 같이 DialogFragment를 재정의 하십시오.
@Override
public void onStart()
{
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
{
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}
이 게시물에 대단히 감사드립니다 : 안드로이드의 신비-전체 화면-대화-조각
답변
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL,
android.R.style.Theme_Black_NoTitleBar_Fullscreen);
}
답변
이 링크 DialogFragment 전체 화면에 측면에 패딩 이 표시되면 매력처럼 작동합니다.
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
// the content
final RelativeLayout root = new RelativeLayout(getActivity());
root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// creating the fullscreen dialog
final Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(root);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return dialog;
}
답변
스타일 만 사용하여 전체 화면 DialogFragment 만들기
첫 번째 해결책
당신에 추가 1 style.xml
:
<style name="FullScreenDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:padding">0dp</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
2. DialogFragment에 추가하십시오 :
@Override
public int getTheme() {
return R.style.FullScreenDialog;
}
대체 솔루션
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.AppTheme)
}
AppTheme
스타일로 정의한 테마는 어디에 있습니까 ?
답변
제 경우에는 다음 접근법을 사용했습니다.
@Override
public void onStart() {
super.onStart();
getDialog().getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}
}
또한 모든 공간을 내용으로 채우는 LinearLayout.
그러나 대화 상자의 왼쪽과 오른쪽 가장자리와 일부 Lollipop + 장치 (예 : Nexus 9)의 화면 가장자리 사이 에는 여전히 작은 간격 이있었습니다 .
분명하지는 않았지만 마침내 모든 장치와 플랫폼에서 전체 너비 로 만들려면 창 배경 이 다음과 같이 styles.xml 안에 지정되어야한다는 것을 알았습니다 .
<style name="Dialog.NoTitle" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:padding">0dp</item>
<item name="android:windowBackground">@color/window_bg</item>
</style>
물론이 스타일은 다음과 같은 대화 상자를 만들 때 사용해야합니다.
public static DialogFragment createNoTitleDlg() {
DialogFragment frag = new Some_Dialog_Frag();
frag.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Dialog_NoTitle);
return frag;
}
답변
전체 화면 대화 상자를 사용할 때 문제가 발생했습니다 .Fragment : 전체 화면을 설정하는 동안 항상 패딩이 있습니다. dialogFragment의 onActivityCreated () 메소드 에서이 코드를 사용해보십시오.
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
Window window = getDialog().getWindow();
LayoutParams attributes = window.getAttributes();
//must setBackgroundDrawable(TRANSPARENT) in onActivityCreated()
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
if (needFullScreen)
{
window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}
}