How to change text size of dialog preference message? - android

I have a class that extends EditTextPreference and I use it in my own layout, such as:
<com.app.MyEditTextPreference
android:key="#string/key"
android:title="#string/title"
android:summary="#string/summary"
android:dialogTitle="#string/title"
android:dialogMessage="#string/message"
android:layout="#layout/preference_edittext"/>
My app theme inherits from Theme.AppCompat.Light.DarkActionBar and I have changed the values of the text sizes:
<style name="TextAppearance.Small">
<item name="android:textSize">18sp</item> <!-- was 14sp -->
</style>
However, when the preference dialog is displayed, the size of the message is different than the one I have defined in my style.
So how do I set the text size of the dialog message correctly?
EDIT
I copied the dialog layout from the sdk:
<LinearLayout
android:id="#+android:id/edittext_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:orientation="vertical">
<TextView
android:id="#android:id/message"
android:layout_marginBottom="48dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:textColor="?android:attr/textColorSecondary"
style="#style/TextAppearance.Small" />
</LinearLayout>
However, I get a build error Resource is not public on the line android:id="#+android:id/edittext_container".
And if I change it to "#*android:id/edittext_container", the edit text is not visible anymore.
Is there a simpler way to just change the textsize of the message?

First create new xml file name cus.xml in layout folder.
it need for set the view for dialog at runtime .
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Name :"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="18dp" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="18dp" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:textSize="18dp" />
As you need dialog:
here's dialog code:
Dialog d=new Dialog(getActivity());
d.setTitle("Image Title");
d.setContentView(R.layout.cus);
d.show();

I finally managed to change the message text size by:
a) Changing the id of the LinearLayout to: #+id/edittext_container, and
b) Adding the following code in my class extending EditTextPreference:
#Override
protected void onAddEditTextToDialogView(View dialogView, EditText editText) {
ViewGroup container = (ViewGroup) dialogView
.findViewById(R.id.edittext_container);
if (container != null) {
container.addView(editText, ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
}
This works fine and is clearly a valid answer, however a simpler solution would be to just change the message text size through themeing.

Related

Use default title text view style for customize title text for AlertDialogs

I was needed to create a custom title view to be able show message and title, when the list appears. Because the list appears in the dialog's content area. So the dialog cannot show both a message and a list.
My custom view is a LinearLayout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="24dp"
android:paddingBottom="20dp"
style="#style/Base.Theme.AppCompat.Dialog.Alert"
>
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:textSize="20sp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/alert_dialog_custom_message_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"/>
</LinearLayout>
Padding values and text size was given in accordance with the information given material design guidelines
However, This appearance is different from the default one.
my question:
How can I create a textView that has a same style with default one ?
Maybe there is a way like setting a style to my TextView
Edit : I just want to set style attribute that makes its visuality same as default AlertDialog.
My textview is already like this:
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="messsage"
android:layout_marginBottom="20dp"
android:textSize="20sp"
android:textStyle="bold"
/>
I want to do that just like this :
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="messsage"
style="?android:attr/titleTextStyle"
/>
In your style you can use this
<style name="TextAppearance.AlertDialogPro" parent="android:TextAppearance" />
for you textview you can add style
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="messsage"
style="#style/TextAppearance.AlertDialogPro"
android:layout_marginBottom="20dp"
android:textSize="20sp"
android:textStyle="bold"
/>

Layout Design with Pop-up

In Android App, I have a card game designed with the Linear layout and image buttons. On completing a level in this game I have to do the following things as listed below...
I have to show a dialog like screen which should pop up on middle of screen. This pop-up should hold some background image and buttons on it. The pop-up should fly from bottom-up.
The card game parent screen should be blurred this this pop-up is shown.
I have seen the similar kind of effects in showing ads from Appflood.
Could you please give some suggestion to this effectively.
Parent Screen
With Pop-Up
Thanks in Advance..
Try that:
Don't use AlertDialog, you can use one normal layout and one normal class. ¿How?
It's easy, you have one class called "FirstActivity.java", and one second class called "SecondActivity.java".
FirstActivity
Designed this class as you like
SecondActivity
You are going to create your own popup with ImageView,Buttons and textviews and you are going to Overlay your layout background.
Popup_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="#drawable/popup_background" />
<ImageView
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="39dp"
android:layout_marginTop="72dp"
android:onClick="go"
android:src="#drawable/ok" />
<TextView
android:id="#+id/question"
android:text:"level completed"
</RelativeLayout>
manifest
Declare SecondActivity with custom Theme.
......
<activity
android:name="com.example.comandero.SecondActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Overlay" />
.......
Styles.xml
Add new style for background on your layout.
<style name="Theme.Overlay" parent="android:style/Theme.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:background">#android:color/transparent</item>
</style>
Try it and say me please. If you dont understand something say me.
I have a very simple solution (and I tested it - it works pretty well, as illustrated by the pictures I posted).
Imagine you have an invisible (GONE) generic View that covers the whole screen (match_parent, match_parent) and has a reddish semitransparent color.
It would become VISIBLE before showing the Dialog and GONE again after dismissing it.
Since it's GONE, you don't see it and it doesn't waste any space until it becomes VISIBLE.
This approach requires the outer container being a FrameLayout or a RelativeLayout (by setting the View properly: anchoring it to the four Parent's corners).
I used a RelativeLayout - because I really love these containers.
dlg_red_bg.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:padding="8dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#android:color/black"
android:padding="8dp"
>
<Button
android:id="#+id/btnTopLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:background="#drawable/ball"
android:text="Btn 1"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold"
/>
<Button
android:id="#+id/btnTopRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/btnTopLeft"
android:background="#drawable/ball"
android:text="Btn 2"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold"
/>
<Button
android:id="#+id/btnBottomLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/btnTopLeft"
android:layout_alignParentLeft="true"
android:background="#drawable/ball"
android:text="Btn 3"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold"
/>
<Button
android:id="#+id/btnBottomRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/btnTopRight"
android:layout_toRightOf="#id/btnBottomLeft"
android:background="#drawable/ball"
android:text="Btn 4"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold"
/>
<Button
android:id="#+id/btnDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/ball"
android:onClick="clickHandler"
android:text="Dialog"
android:textColor="#android:color/white"
android:textSize="24sp"
android:textStyle="bold"
/>
</RelativeLayout>
<View
android:id="#+id/vwRedOver"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="#8f00"
android:visibility="gone"
/>
</RelativeLayout>
code used to highlight the background
public void clickHandler(final View v)
{
switch(v.getId())
{
case R.id.btnDialog:
{
vwRedOver.setVisibility(View.VISIBLE);
final AlertDialog.Builder bld = new AlertDialog.Builder(this);
bld.setMessage("Some Message")
.setCancelable(true)
.setPositiveButton
(
"OK",
new DialogInterface.OnClickListener()
{
#Override
public final void onClick
(final DialogInterface dlg, final int id)
{
vwRedOver.setVisibility(View.GONE);
dlg.cancel();
}
}
)
.setNegativeButton
(
"Cancel",
new DialogInterface.OnClickListener()
{
#Override
public final void onClick
(final DialogInterface dlg, final int id)
{
vwRedOver.setVisibility(View.GONE);
dlg.cancel();
}
}
);
bld.create().show();
}
}
}
result
Before Clicking on "Dialog"
After Clicking on "Dialog"
NOTE 1: It's dark because of the black background
NOTE 2: You see a black border, because I set a padding on the outer RelativeLayout - you can remove it
After Clicking on either "OK" or "Cancel" - returns to the initial state (my Dialog doesn't do anything interesting on OK - It's only for demo purposes)

Android: Using default style in a custom dialog title

I'm trying to create a custom multiple choice alert dialog that allows the user to select/deselect all items in one click.
I achieve this using a custom title with an additional checkbox.
Everything works fine except that I don't know how to make my custom title looking like the default alert dialog title (using the same style).
Here is what I'm trying to do (The example uses the theme in the Dialogs documentation. That's just an example, what I really try to have is the application theme).
I created a custom view for the custom title I use, but I don't know how to get the attributes of the default style title bar, so, I obtain:
(No blue bar below the title, and wrong title color)
Here is the layout of my custom title:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/title"
style="?android:attr/textAppearanceLarge"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Dialog title" />
<TextView
android:id="#+id/all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
It seems obvious to me that I need to define the title attributes, and the background of the layout ... but I'm crawling the web since hours searching how to get the attributes of default title view.
Any idea?
See if this is what you are looking for:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="22sp"
android:textColor="#ff33b5e5"
android:text="Dialog title" />
<TextView
android:id="#+id/all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All" />
<CheckBox
android:id="#+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<View android:id="#+id/titleDivider"
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="#ff33b5e5" />
</LinearLayout>
How I got this:
Browse to the sdk directory on your hard drive > platforms > android-XX(17, for example) > data > res > layout > dialog_title_holo.xml. Look at the View with id titleDivider. It's background attribute: background="#android:color/holo_blue_light". Look up the value of this color in res/values/colors.xml.
From styles_device_defaults.xml:
<style name="TextAppearance.DeviceDefault.DialogWindowTitle" parent="TextAppearance.Holo.DialogWindowTitle" >
Looking at styles.xml:
<style name="TextAppearance.Holo.DialogWindowTitle">
<item name="android:textSize">22sp</item>
<item name="android:textColor">#android:color/holo_blue_light</item>
</style>
The textColor is the same as the line color. Text size is specified as 22sp. And, style="?android:attr/textAppearanceLarge" is not required because we are setting the textSize="22sp":
<style name="TextAppearance.Large">
<item name="android:textSize">22sp</item>
</style>
If you just want to use the device default, without needing to customize or extend anything, you can simply add:
android:textAppearance="#android:style/TextAppearance.DeviceDefault.DialogWindowTitle"
to the title view in your xml layout. This will show a different style based on the devices theme.
If you ALWAYS want to show the blue (Holo Theme) title, regardless of the device defaults, then you can add:
android:textAppearance="#android:style/TextAppearance.Holo.DialogWindowTitle"
instead.

Android: Custom AlertDialog has different text color

I created a custom layout for an AlertDialog, and it works fine,
But i have a problem with the text style of my layout.
This is the layout for my alertDialog:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/namedialoglable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/profilename" />
<EditText
android:id="#+id/namedialoginput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/namedialoglable"
android:layout_marginTop="24dp"
android:ems="10"
android:selectAllOnFocus="true"
android:text="#string/defaultname" >
<requestFocus />
</EditText>
</RelativeLayout>
The problem is that the text into the default AlertDialog is white, and in my custom dialog is black. I just want to use the same color used into other AlertDialog.
How to do that?
EDIT
To be more clear:
I want to keep the father text color, not force my custom dialog color to be white. I think that AlertDialog use system color, so my alert need to keep the same color
Why wont you just apply:
android:textColor="#android:color/white"
to the Views you want with while text color.
Also look into styles and themes to achieve what you wnat:
http://developer.android.com/guide/topics/ui/themes.html#PlatformStyles
Ok in my case, i found another solution.
Since my need is to have only a message and an input text into the dialog box, the best solution is to create a layout with only an EditText, like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/namedialoginput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="24dp"
android:ems="10"
android:selectAllOnFocus="true"
android:text="#string/defaultname" >
<requestFocus />
</EditText>
</RelativeLayout>
And for the message text, using the builder method: setMessage:
builder.setView(content)
.setTitle("Profile Name")
.setMessage(R.string.profilename);
In that way, i am sure that i keep the other dialog boxes format.

Android 3.1 Dialog not the right size

I am creating a custom dialog in my app and it looks fine in the Layout Editor, but is not the right size on the device. Here's the layout for the dialog:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/dialog_border"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:padding="10dp"
android:src="#drawable/wifi" />
<TextView
android:layout_height="wrap_content"
android:id="#+id/heading"
android:layout_below="#+id/image"
android:layout_width="wrap_content"
android:layout_margin="10dp"
android:layout_alignLeft="#+id/cancel_button"
android:layout_alignRight="#+id/continue_button"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/lost_connection"
android:layout_centerHorizontal="true" />
<TextView
android:layout_height="wrap_content"
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_below="#+id/heading"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_centerHorizontal="true"
android:layout_alignLeft="#+id/cancel_button"
android:layout_alignRight="#+id/continue_button"
android:gravity="center"
android:layout_margin="10dp"
android:text="#string/try_again" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/cancel_button"
android:layout_below="#+id/description"
android:layout_centerHorizontal="true"
android:id="#+id/dismiss_button"
android:text="#string/dismiss" />
</RelativeLayout>
This is what it looks like in the Layout Editor:
But this is what it looks like on the device:
It has that weird bit of extra space at the top and right side and the button is compress vertically.
That blank area is the dialog title. It can be turned off when creating the DialogFragment as:
DialogFragment df = new MyDialogFragment();
df.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
df.show(ft, "dialog");
Where the 0 in set style lets the platform choose an appropriate style and "dialog" is whatever tag you'd like to set for your dialog fragment.
I think that extra weird space at the top is the place for the dialog title. As i see on the screenshots you used a dialog and inflated a custom view into that dialog ?
I guess worth a try to hide the title of the dialog with yourDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);

Categories

Resources