android - 将对话框 fragment 标题设置为从右侧显示

标签 android android-layout dialog titlebar

我正在用希伯来语(即 rtl)编写一个应用程序。 当我为对话框 fragment 设置标题时,它出现在左侧。 我试图通过以下方式使其显示在右侧:

@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);

但不影响标题的位置。 我怎样才能做到这一点? TNX

最佳答案

隐藏默认标题并在布局中制作自定义标题。

隐藏默认标题:

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

然后使用您喜欢的样式将 TextView 添加到布局的顶部:

<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" />

关于android - 将对话框 fragment 标题设置为从右侧显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10470238/

相关文章:

javascript - showAlert 删除我的 ID

android - acct文件夹android

android - 更改 TextInputLayout 提示字体

android - 如何忽略 ListView 行中的点击

java - 从共享首选项恢复日期并显示 Android 中内联日期选择器的更改

java - 从 DialogFragment 调用 FileProvider 时出错 - 引用对象为空,

android - 如何在 Google Maps API v2 中禁用标记触摸时的自动平移

具有视差背景图像的 Android ViewPager

android - View 在 CardView 中被标记

java - 自定义对话框构造函数