0

I've read some question related to this topic and tried some code examples. My min API level is 11. Some approaches was to get their id based on the layout source code: dialog layout

I tried to obtain the TextView using simple this code in my DialogFragment:

    int titleTextId = getResources().getIdentifier("android:id/alertTitle", null, null);
    TextView titleText = (TextView)getDialog().findViewById(titleTextId);
    titleText.setTextColor(ContextCompat.getColor(getActivity(), R.color.darkerOrange));
    if(titleText != null){
        Log.d("DEBUG", "FOUNDED");
    }

This is my styles.xml file:

<resources>
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarStyle">@style/MyActionBar</item>
    <item name="android:alertDialogTheme">@style/DialogTitleText</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="titleTextStyle">@style/TitleBarTextColor</item>
    <item name="background">@color/white</item>
</style>

<style name="TitleBarTextColor" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@color/darkerOrange</item>
</style>

<style name="DialogTitleText" parent="@style/Theme.AppCompat.Light.Dialog">
    <item name="android:windowTitleStyle">@style/DialogTitleStyle</item>
</style>

<style name="DialogTitleStyle" parent="@style/DialogTitleText">
    <item name="android:textColorPrimary">@color/darkOrange</item>
</style>

<style name="SplashScreen" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screen</item>
</style>

<style name="TabLayoutTextSize" parent="TextAppearance.Design.Tab">
    <item name="android:textSize">20dp</item>
</style>

My AndroidManifest.xml

<application
    ...
    android:theme="@style/AppTheme">
    ...

These are visited links:

How to style AlertDialogs like a pro

Android - DialogFragment change title text color

Styling custom dialog fragment not working

Android change toolbar title color to white

Even with these approaches I haven't successfully changed title color. And I want 'to preserve min API to 11. Is this related to this min API?

Community
  • 1
  • 1
learner
  • 1,311
  • 3
  • 18
  • 39
  • I've been dealing with something similar, and I think this title is for quick dialog setup. For anything custom go with dialog body implementation. You can define layout for dialog body (put title inside), and remove setTitle() from dialog builder. This title is just TextView with padding and different size, so it is easy to replicate it. – JoKr Aug 29 '16 at 17:13
  • Thanks for your reply. I followed it and solve the problem. I'll put the answer now. – learner Aug 29 '16 at 17:22

1 Answers1

0

Following advice from @Gudin I searched and found the title layout source:

DialogFragment title layout

I appliced the source code to find the view and it works.

Change this line: getResources().getIdentifier("android:id/alertTitle", null, null);

To this: getResources().getIdentifier("title", "id", "android");

learner
  • 1,311
  • 3
  • 18
  • 39