Skip to content

Instantly share code, notes, and snippets.

@mobiRic
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mobiRic/feddbf7cd8f6b2f75129 to your computer and use it in GitHub Desktop.
Save mobiRic/feddbf7cd8f6b2f75129 to your computer and use it in GitHub Desktop.
Android hack to change the colour of the divider line in a Dialog
/*
* Copyright (C) 2014 Glowworm Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package lib.widget;
import android.app.Dialog;
import android.content.res.Resources;
import android.view.View;
/**
* Helper class that uses a HACK to change the divider line in a dialog. </p>
*
* A better method would be to use a library such as
* https://github.com/inmite/android-styled-dialogs.
*/
public class DialogHack
{
/**
* HACK to change the colour of the divider line. Must be called on a dialog that has already
* been shown.
*/
public static void setTitleDividerColor(Dialog dialog, int color)
{
Resources resources = dialog.getContext().getResources();
int dividerId = resources.getIdentifier("android:id/titleDivider", null, null);
View divider = dialog.findViewById(dividerId);
if (divider != null)
{
divider.setBackgroundColor(color);
}
}
}
@mobiRic
Copy link
Author

mobiRic commented Dec 5, 2014

Helper class that uses a HACK to change the divider line in a dialog.

A better method would be to use a library such as https://github.com/inmite/android-styled-dialogs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment