2014-03-31 4 views
2

DialogFragment에 작업 표시 줄을 추가하는 방법은 무엇입니까? 우리가 필요로하는 방식으로 액티비티를 스타일링하고 다음 링크와 같이 대화 상자로 표시하는 방법을 찾았습니다. ActionBar in a DialogFragment 적절한 조치 모음을 설정해야합니다. DialogFragment. 가능한가? 가 표시DialogFragment에 작업 표시 줄을 추가하는 방법은 무엇입니까?

+0

아니요. 특별히'ActionBar'가 필요한 이유는 무엇입니까? – adneal

+0

고맙습니다. 고맙습니다. 작업 표시 줄을 조각에 추가 할 수 있으며 대화 상자 조각은 조각 클래스의 하위 클래스이므로 문제를 해결할 수있었습니다. –

+0

대신 도구 모음을 첨부하는 방법이 있습니다.이 방법은 작업 표시 줄과 거의 동일합니다. 여기 : http://stackoverflow.com/a/38917527/878126 –

답변

4

Up ActionBar action on DialogFragment으로 : 당신이 그것에 액션 바로 등록되지 않습니다 DialogFragment의 테마를 설정할 수 있습니다 경우에도 DialogFragment에 액션 바를 부착 할 수있는 방법은 없습니다, Dialog.getActionBar()는 항상 null를 돌려줍니다.

하지만 항상 Activity 대신 DialogFragment (스타일처럼 ActionBar가 포함되어 있음)를 사용하려는 경우가 항상 있습니다.)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/white" > 

<include android:id="@+id/fake_action_bar" 
    layout="@layout/fake_action_bar_with_backbotton" /> 

2 about_dialog.xml 레이아웃과 같은 액션 바 구현 : 1) DialogFragment 레이아웃 : 그냥 단계를 DialogFragment의 레이아웃

다음 내로 액션 바처럼 보일 것 레이아웃입니다 추가 fake_action_bar_with_backbotton을. XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/fake_action_bar" 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:minHeight="?attr/actionBarSize" 
    app:navigationIcon="@drawable/ic_menu_back" 
    android:background="@color/background_material_dark" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

참고 : @ 드로어 블/ic_menu_back이 SDK의 \ 플랫폼에서 복사는 안드로이드-21 \ 데이터 \ \ 고해상도

당김-hdpi에 \3210

3)

public class AboutDialogFragment extends DialogFragment { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // use Theme_Holo_Light for full screen 
     // use Theme_Holo_Dialog for not full screen 
     // first parameter: DialogFragment.STYLE_NO_TITLE no title 
     setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Holo_Light_DarkActionBar); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View v = inflater.inflate(R.layout.about_dialog, container, false); 

     // set the listener for Navigation 
     Toolbar actionBar = (Toolbar) v.findViewById(R.id.fake_action_bar); 
     if (actionBar!=null) { 
      final AboutDialogFragment window = this; 
      actionBar.setTitle(R.string.about_title); 
      actionBar.setNavigationOnClickListener(new View.OnClickListener() { 
       public void onClick(View v) { 
        window.dismiss(); 
       } 
      }); 
     } 
     return v; 
    } 
} 

가 도울 수 원하는 DialogFragment 코드를 업데이트!

관련 문제