androidandroid-layoutdialogtitlebar

set dialog fragment title to display from right


I'm writing an app in Hebrew (which is rtl). when I set my title for the dialog fragment it appears on the left. I tried to make it display on right by doing:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState)
{
    //set's up the title for this dialog fragment
    getDialog().getWindow().setGravity(Gravity.RIGHT);
    getDialog().setTitle(R.string.find_Address_text);

but it doesn't affect the position of the title. how can i achieve this? TNX


Solution

  • Hide the default title and make a custom one in the layout.

    To hide the default title:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(STYLE_NO_TITLE, 0); // remove title from dialogfragment
    }
    

    Then add a TextView to the top of layout with your preferred styling:

    <TextView
     android:id="@+id/dialog_title"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:gravity="right|center"
     android:text="@string/dialog_title" />