Textview: using the dialog title style: @android:style/TextAppearance.DialogWindowTitle

隐身守侯 提交于 2019-12-03 01:35:09

Maybe you can extend the default style in this manner:

res/values/dialogstyles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Dialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowTitleStyle">@style/MyOwnDialogTitle</item>
    </style>
    <style name="MyOwnDialogTitle">
        <item name="android:drawableRight">@drawable/MyRightImage</item>
    </style>
</resources>

res/values-v11/dialogstyles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
     <style name="Dialog" parent="@android:style/Theme.Holo.Dialog">
          <item name="android:windowTitleStyle">@style/MyOwnDialogTitle</item>
     </style>
</resources>

And override your DialogFragment's onCreate:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog);
}

Working Example

I am searching for your first requirement. but for second requirement, why dont you try with changing the color to style of the TextAppearance.DialogWindowTitle with your custom style ?

I have just check the android resources where there is style like below:

  <style name="DialogWindowTitle">
    <item name="android:maxLines">1</item>
    <item name="android:scrollHorizontally">true</item>
    <item name="android:textAppearance">@style/TextAppearance.DialogWindowTitle</item>
</style>

and for TextAppearance.DialogWindowTitle style:

 <style name="TextAppearance.DialogWindowTitle">
    <item name="android:textSize">18sp</item>
    <item name="android:textStyle">normal</item>
    <item name="android:textColor">?textColorPrimary</item>
</style>

Now, you can change the color of your TextAppearance.DialogWindowTitle style and do as you want.

Hope you got the point.

Feel free to comment.

Have you tried to use @android:style/Theme.Holo.Light.Dialog as your parent in styles? This will work only in Android 3+ because in earlier version there is no theme Holo, but you can create your own to look like it for lower versions of Android.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!