I'm trying to create a custom dialog box but it's both making it as wide as the screen (minus padding) but more importantly it's adding about an inch to the top in white (the background colour is red) above the first textview. What I want is a dialog box just as big as it needs to fill the content.
If I change any layout from fill_parent to wrap_content I get the contents about the size of the image and everything else (i.e. the text) is truncated.
What am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/customdialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/titledialog"
android:orientation="vertical" >
<TextView
android:id="#+id/textTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/titleback"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="24dp"
android:paddingTop="48dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="TextView" />
</LinearLayout>
<Button
android:id="#+id/buttonCustomDialogOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Close" />
I found the answer here
Android: How to create a Dialog without a title?
Apparently the top blank bit is the title of the layout and you cannot get rid of it unless you use an AlertDialog and not a Dialog.
ah, thanks for the update.
Android Dialog: Removing title bar
you can do it like this
Dialog dialog = new Dialog(context, R.style.FullHeightDialog);
(OR Try This)
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
Related
I am developing an Android app. It is just like an article reading app in which there are many textview (more than 10) under one activity.
Like -
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="#dimen/activity_vertical_margin" android:paddingLeft="#dimen/activity_horizontal_margin" android:paddingRight="#dimen/activity_horizontal_margin" android:paddingTop="#dimen/activity_vertical_margin" tools:context=".EnviarMensaje">
<TextView android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My text is here" android:textSize="20sp" />
<TextView android:id="#+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My text is here" android:textSize="20sp" />
<TextView android:id="#+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My text is here" android:textSize="20sp" />
</RelativeLayout>
I want to make all these textview selectable when user touch for a long time on text, an option should come "select all". And when choosing the select all option, the Text of all Textview (From textView 1 to textView3) should select.
I tried - android:textIsSelectable=true
But after apply this, when I choose select all option, the Text is selected of only textView1 or textView2. Not selected all text on screen together.
Please help me.
Checkout this: https://stackoverflow.com/a/6179365
You can register the textviews in onCreate, then override onCreateContextMenu and getTextfrom each textview.
I am developing custom menu item by calling action layout, but when i am taping that action menu that pressing color is not applying total height giving some top and bottom margin.
Below is my code:
<?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:gravity="center">
<ImageView
android:minWidth="56dp"
android:id="#+id/voicemailNotificationCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:clickable="true"
android:background="#drawable/ab_pressedicon_bgcolor"
android:contentDescription="#string/voicemailnotification"
android:src="#drawable/ab_voicemail">
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/vmNotificationTextCounter"
android:text="1"
android:visibility="visible"
android:layout_alignRight="#+id/voicemailNotificationCounter"
android:layout_marginRight="10dp"
android:gravity="center"
android:textColor="#fff"
android:includeFontPadding="false"
android:background="#drawable/notification_alertbg"
android:textSize="12sp"/>
</RelativeLayout>
Part of the problem is that you're not using an ImageButton.
Combining an image with text is possible with an ImageButton. You can even independently adjust the text and the image inside that ImageButton.
Hopefully, an ImageButton will work inside an action menu, I haven't actually tested that part yet.
I have a Button with a background drawable, android:layout_width="wrap_content" and android:layout_height="wrap_content". There is no text on the button. However, its display size is such that the drawable is resized a little bit and looks blurry, unless I set width and height to those of the drawable in px. How can I make wrap_content work? Or any other way that doesn't involve hard-coding the size of button, so that I don't need to make additional edits when the size of the drawable changes?
Here's my XML:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingTop="3dp" >
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/btn" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Use ImageButton instead of the regular Button. It provides access to the property android:src and set your image there, instead of as a background. Background images are always fit-to-fill, where as the "source" property controls image resizing via the android:scaleType property. See: http://developer.android.com/reference/android/widget/ImageButton.html and http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType
Note, for your ImageButton, you'll also need to be sure that android:background="#null", otherwise you'll see the default button image behind your source image.
Edit:
Here is an updated version of your XML. I've added a new button, above the one you started with, although I used one of my images. The particular image is long and not that tall. In the regular Button, it stretches to fill the widget, losing perspective. In the new ImageButton to the top, it maintains it's perspective.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="3dp"
android:paddingTop="3dp" >
<ImageButton
android:id="#+id/new_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:scaleType="fitCenter"
android:src="#drawable/postwall" />
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/new_btn"
android:background="#drawable/postwall" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
I have an app that I am putting together and I have a background on it. There is a header on top and a ListView in the middle. When I have a list in the middle that isn't at least as big as the screen it just shows gray not the background of the parent layout. The weird thing is that this doesn't happen on my older phone, the background fills the whole screen even if the list doesn't. Here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- This is the xml for HomeActivity, more information in HomeActivity.java -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/common_aboutLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg">
<!-- This is the header on the top of the home screen -->
<LinearLayout android:id="#+id/dynamicBanner"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/header"
android:layout_width="fill_parent">
<!-- This is the temp pop-up on start -->
<TextView android:text="#+id/TextView01"
android:id="#+id/titleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:textColor="#FFFFFF"
android:visibility="invisible"
android:textStyle="bold"
android:typeface="sans"
android:ellipsize="end"
android:textSize="18sp"
android:gravity="center_vertical|center_horizontal">
</TextView>
</LinearLayout>
<!-- This is the layout of the list of ringtones. -->
<ListView android:id="#+id/homeListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
<LinearLayout android:id="#+id/adLayout"
android:layout_width="fill_parent"
android:layout_height="0dp">
<com.admob.android.ads.AdView android:id="#+id/ad"
admob:textColor="#FFFFFF"
admob:keywords="Android application"
android:layout_width="fill_parent"
android:layout_gravity="bottom|center"
admob:backgroundColor="#666666"
admob:refreshInterval="30"
android:layout_height="0dp" />
</LinearLayout>
</LinearLayout>
The TextView is just a temp thing when the window first opens.
Just looking for some help, Thanks.
put All views in RelativeLayout.then put this admob layout and add a tag to plcae this to bottom of layout
like
android:layout_alignParentBottom="true"
<LinearLayout android:id="#+id/adLayout"
android:layout_width="fill_parent"
android:layout_height="0dp">
<com.admob.android.ads.AdView android:id="#+id/ad"
admob:textColor="#FFFFFF"
admob:keywords="Android application"
android:layout_width="fill_parent"
android:layout_gravity="bottom|center"
admob:backgroundColor="#666666"
admob:refreshInterval="30"
android:layout_height="0dp" />
</LinearLayout>
and then Header part inside the relative layout
android:layout_alignParentTop="true"
and the put the ListView and
android:layout_above="#+id/adLayout"
android:layout_below=HEADERVIEW
i want to display two buttons at the bottom of my activity screen, but each time i populate the screen with views that makes me scroll, the two buttons at the bottom of my screen disappears. when there is no need to scroll the buttons display fine.
please help
thanks.
Layout code
?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/lin_layout_list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:isScrollContainer="true"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ListView android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2px"
android:layout_gravity="bottom"
>
<TableLayout
android:layout_below="#id/lin_layout_list_view"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_width ="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1">
<TableRow
android:orientation="horizontal">
<Button android:id="#+id/ws_button_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Back "
/>
<Button android:id="#+id/ws_button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Ok "/>
</TableRow>
</TableLayout>
</RelativeLayout>
</LinearLayout>
Wrap the buttons along with the scrollable content(e.g:-Listview) in a scrollview and then display the content.