Create Dialog-link popup for text message link HandcentSMS - android

I'm in the middle of modifying a test message application and one of the features that I'd like to add to it would be that when a text message is received, a dialog box of some sort would pop up with the text message stuff and the ability to quickly reply to it, all without having to go into the actual application. Taking HandcentSMS as an example, here is what I'm talking about:
Any ideas how to go about doing this, or could anyone point me in a good direction to get started on this?

You can make an activity, and style it with custom style which should inherit Theme.Dialog
Example style:
<style name="Theme.MyDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">#android:drawable/alert_light_frame</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:overScrollMode">never</item>
<item name="android:windowNoTitle">true</item>
</style>
The most important thing is to prepare xml layout of the activity properly.
I suggest to WRAP_CONTENT for everything vertically, and FILL_PARENT horizontally.
Sample layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="280dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/frg_alert_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/topbar_logo"
android:drawablePadding="10dp"
android:gravity="center_vertical"
android:padding="10dp"
android:text="Title"/>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#android:drawable/divider_horizontal_bright"/>
</LinearLayout>
<FrameLayout
android:id="#+id/customPanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone">
<FrameLayout
android:id="#+id/custom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
<ScrollView
android:id="#+id/messagePanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:padding="10dp">
<TextView
android:id="#android:id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Some text"/>
</ScrollView>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#android:drawable/divider_horizontal_bright"/>
<LinearLayout
android:id="#+id/frg_alert_three_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:visibility="gone"
android:weightSum="3">
<Button
android:id="#+id/button_positive"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:maxLines="2"
android:minLines="2"
android:text="Button"/>
<Button
android:id="#+id/button_neutral"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:maxLines="2"
android:text="Button"/>
<Button
android:id="#+id/button_negative"
style="?android:attr/buttonStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:maxLines="2"
android:text="Button"/>
</LinearLayout>
<LinearLayout
android:id="#+id/frg_alert_two_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="#dimen/screenPadding"
android:weightSum="2">
<Button
android:id="#+id/button_positive"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="2"
android:minLines="2"
android:text="Button"/>
<Button
android:id="#+id/button_negative"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:maxLines="2"
android:minLines="2"
android:text="Button"/>
</LinearLayout>
</LinearLayout>

for Create this UI just Create an Activity with background transparent as:
Step 1: add res\values\style.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Smspopuptheme" 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>
</resources>
Step 2: add theme to in AndroidManifest.xml for activity which u want to show with message as:
<activity
android:label="#string/app_name"
android:theme="#style/Theme.D1NoTitleDim"
android:name=".SmspopuptestActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Step 3: In SmspopuptestActivity.java set FEATURE_NO_TITLE before setContentView as:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
//this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
Step 4: Your Activity layout look like res/layout/main.xml :
<?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:background="#55000000"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/frg_alert_buttons"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#android:color/darker_gray"
android:gravity="center"
android:padding="5dp"
android:layout_centerInParent="true"
android:weightSum="3">
</LinearLayout>
</LinearLayout>
add your layout elements in frg_alert_buttons likes Buttons, Textviews,Imageview and EditViews as per your need.
Start SmspopuptestActivity.java Activity when you receive new SMS.
Some helpful resources:
android-listen-for-incoming-sms-messages
SOME SOUCE CODE FOR SMSPOPUP IN ANDROID:
droid-notify
android-smspopup
showsms
smspopup-for-android

Related

Why the layout_below is invalid that running on the phone?

This is my layout. My question is that the id is "below_button" LinearLayout is invalid that running on the phone. The phone didn’t display this LinearLayout, but others layout is right. How come?
<?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">
<include
android:id="#+id/title"
layout="#layout/toptitlebar" />
<LinearLayout
android:id="#+id/query_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="#+id/title"
android:background="#e2dfdf"
android:layout_alignParentLeft="true">
<EditText
android:id="#+id/ram_assistinqnum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="0.45"
android:hint="通知书编号"
android:maxLines="1"
/>
<TextView
android:id="#+id/ram_operate_date"
style="#style/SpinnerCtl_Wrap"
android:gravity="center"
android:layout_margin="10dp"
android:layout_weight="0.45"
android:hint="操作时间"
android:textColor="#color/black"/>
<ImageView
android:id="#+id/ram_query"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.1"
android:src="#drawable/ram_query"
android:layout_margin="10dp"/>
</LinearLayout>
<com.sdrcu.operatingdecisions.view.scrollabletbv.ScrollTableView4
android:id="#+id/scrollTableView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/query_detail"
/>
<LinearLayout
android:id="#+id/below_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#e2dfdf"
android:layout_below="#+id/scrollTableView"
>
<ImageView
android:id="#+id/ram_arrow_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_weight="0.3"
android:src="#drawable/ram_arrow_previous"/>
<TextView
android:id="#+id/paging"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:gravity="center"
android:text="翻页"
android:textColor="#color/text_blue"
android:textSize="20sp"
/>
<ImageView
android:id="#+id/ram_arrow_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_weight="0.3"
android:src="#drawable/ram_arrow_next"/>
<ImageView
android:id="#+id/ram_agree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:src="#drawable/ram_agree"/>
<ImageView
android:id="#+id/ram_disagree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:src="#drawable/ram_disagree"/>
</LinearLayout>
</RelativeLayout>
#Seal
In my layout editor's Preview I changed the "Theme in Editor" to "Theme"
And I started to get errors like your screenshot.
See:
So, I selected "All" -> "AppTheme" from the "Theme in Editor" option... Do not forget to press "Ok"
And the errors went away:
So, why do not you also try to set it to "All" -> "AppTheme"
Further it appears to me that you might have created style(s) which do not inherit from "proper parent".
Using below example: "AppTheme" inherits all the required attributes from "Theme.AppCompat.Light.DarkActionBar". And thus, you need to only specify the attributes you need modified.
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
...
<item name="colorAccent">#color/colorAccent</item>
...
</style>
replace
android:layout_below="#id/query_detail"
in
<com.sdrcu.operatingdecisions.view.scrollabletbv.ScrollTableView4
android:id="#+id/scrollTableView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/query_detail"
/>
with
android:layout_below="#+id/query_detail"
yes you miss the parameter height and weight
android:layout_width="match_parent"
android:layout_height="wrap_content"
add in your layout it works Use the Tag

Custom dialog becomes the size of the first control in android

I have the following layout for my custom log in dialog
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/padding_large">
<ImageButton android:src="#drawable/ic_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dialog.login.settings"
android:padding="#dimen/margin_medium" />
<TextView android:text="#string/dialog.login.text.user_name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/dialog.login.user_name"
android:layout_width="match_parent"
android:gravity="center"
android:ems="20"
android:layout_height="wrap_content"
android:inputType="text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView android:text="#string/dialog.login.text.password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/dialog.login.password"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox android:id="#+id/dialog.login.show_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/dialog.login.check.show_password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_margin="#dimen/margin_medium"
android:checked="false" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:id="#+id/dialog.login.cancel"
android:drawableStart="#drawable/ic_exit_black"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_medium"
android:text="#string/dialog.login.button.cancel" />
<Button android:id="#+id/dialog.login.connect"
android:text="#string/dialog.login.button.connect"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_marginStart="#dimen/margin_medium"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
when I create the dialog and setcontentview the width of the dialog becomes equal to that of the image button on the first row
if I remove that , it becomes the size of the EditText (dialog.login.user_name) whose ems is 20
when I make the dialog's constructor call the base dialog constructor with a theme of R.style.Theme.Material.Dialog it does get the correct (about 3/4 of the screen) but the problem is that it ignores my primary and accent colours (which is normal)
Is there a way to have the dialog have the Theme.Material.Dialog size but still keep my own primary/accent colours?
thanks in advance for any help you can provide
After a lot of searching it seems that the solution is to actually replace the dialogTheme attribute of my main theme, so the solution was:
<style name="app.theme"
parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
<item name="android:dialogTheme">#style/app.dialog</item>
......
</style>
<style name="app.dialog"
parent="android:Theme.Material.Light.Dialog">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary.dark</item>
<item name="android:colorAccent">#color/accent</item>
</style>

Android Listview Item : How to set custom height of the item?

I have the following list item layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/AppTheme.ListViewItemStyle_1">
<View android:id="#+id/data_view_stripe"
style="#style/AppTheme.RedStripe"/>
<ImageView android:id="#+id/data_iv_main"
style="#style/AppTheme.ImageBig"
android:src="#drawable/web_icon_weight"
android:contentDescription="Item icon"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="4"
android:padding="4dp"
android:layout_gravity="center">
<TextView android:id="#+id/data_tv_title"
style="#style/AppTheme.ListItemDefaultHeading"
android:text="BP - diastolic"/>
<TextView android:id="#+id/data_tv_value"
style="#style/AppTheme.WrapContent.Value"
android:text="87 mmHg"/>
<TextView android:id="#+id/data_tv_occurence_desc"
style="#style/AppTheme.WrapContent.Calendar"
android:text="Daily at 8:00"/>
<TextView android:id="#+id/data_tv_overdue"
style="#style/AppTheme.WrapContent.Schedule"
android:text="Overdue (Today at 8:00)"/>
<TextView android:id="#+id/data_tv_test_time"
style="#style/AppTheme.WrapContent.Schedule"
android:text="Overdue (Today at 8:00)"/>
</LinearLayout>
<ImageButton android:id="#+id/data_btn_favourite"
style="#style/AppTheme.RatingBasic"
android:paddingLeft="15dp"
android:paddingRight="0dp"
android:contentDescription="Favourite button"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center">
<ImageView android:id="#+id/data_iv_trend"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/ic_arrow_down"
android:contentDescription="Progress indicator"/>
<ImageButton android:id="#+id/data_btn_info"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/background_white"
style="#style/AppTheme.Info"
android:contentDescription="Information button"/>
</LinearLayout>
</LinearLayout>
With the following styles:
<!-- Base ListVIew Item -->
<style name="AppTheme.ListViewItemBase" >
<item name="android:background">#color/background_white</item>
<item name="android:paddingTop">10dp</item>
<item name="android:paddingBottom">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:divider">#android:color/holo_red_dark</item>
<item name="android:dividerHeight">10dp</item>
<item name="android:orientation">horizontal</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_gravity">center</item>
</style>
<!-- ListVIew Item style 01-->
<style name="AppTheme.ListViewItemStyle_1" parent="AppTheme.ListViewItemBase">
<item name="android:layout_height">50dp</item>
<item name="android:descendantFocusability">blocksDescendants</item>
</style>
I tried to set the custom height of the item to 50dp using the:
android:layout_height
Height was changed in Android Studio layout preview, but if i deployed app into real device height of the item stayed unchanged.
How can i set custom height for list item using styles please?
Many thanks for any advice.
EDIT:
By Your suggestion i tried following example which is not working for me (item height is still same).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="20dp"
>
<View android:id="#+id/data_view_stripe"
style="#style/AppTheme.RedStripe"/>
<ImageView android:id="#+id/data_iv_main"
style="#style/AppTheme.ImageBig"
android:src="#drawable/web_icon_weight"
android:contentDescription="Item icon"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="4"
android:padding="4dp"
android:layout_gravity="center">
<TextView android:id="#+id/data_tv_title"
style="#style/AppTheme.ListItemDefaultHeading"
android:text="BP - diastolic"/>
<TextView android:id="#+id/data_tv_value"
style="#style/AppTheme.WrapContent.Value"
android:text="87 mmHg"/>
<TextView android:id="#+id/data_tv_occurence_desc"
style="#style/AppTheme.WrapContent.Calendar"
android:text="Daily at 8:00"/>
<TextView android:id="#+id/data_tv_overdue"
style="#style/AppTheme.WrapContent.Schedule"
android:text="Overdue (Today at 8:00)"/>
<TextView android:id="#+id/data_tv_test_time"
style="#style/AppTheme.WrapContent.Schedule"
android:text="Overdue (Today at 8:00)"/>
</LinearLayout>
<ImageButton android:id="#+id/data_btn_favourite"
style="#style/AppTheme.RatingBasic"
android:paddingLeft="15dp"
android:paddingRight="0dp"
android:contentDescription="Favourite button"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center">
<ImageView android:id="#+id/data_iv_trend"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="#drawable/ic_arrow_down"
android:contentDescription="Progress indicator"/>
<ImageButton android:id="#+id/data_btn_info"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/background_white"
style="#style/AppTheme.Info"
android:contentDescription="Information button"/>
</LinearLayout>
</LinearLayout>
Remove
style="#style/AppTheme.ListViewItemStyle_1"
Where is android:orientation
Then.You can try this way ,
<?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="50dp"
android:orientation="horizontal">
Note:
set android:orientation="" as horizontal or vertical as per your requirement

android Separator after last item of ListView

I have two listviews and two different adapters for them. one shows the bottom divider but the other list does not show divider after the last item.
The one which shows divider after last item, only has listview in the layout. other one which does not shows divider has other views along with the listview.
both listviews have the same style which is below.
<style name="st_comman_data_list">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:background">#color/app_background_color</item>
<item name="android:cacheColorHint">#color/app_background_color</item>
<item name="android:drawSelectorOnTop">true</item>
<item name="android:fadeScrollbars">true</item>
<item name="android:fadingEdge">none</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:listSelector">#drawable/list_states_color</item>
<item name="android:scrollbarFadeDuration">1000</item>
<item name="android:fastScrollEnabled">true</item>
</style>
Edit
layout xml for correct divider
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/app_background_color_light"
android:orientation="vertical" >
<ListView
android:id="#+id/gift_home_ui_home_list"
style="#style/st_comman_data_list"
android:layout_height="match_parent" />
xml which don't shows divider
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/app_background_color"
android:cacheColorHint="#color/app_background_color"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_header"
android:gravity="center"
android:visibility="gone" >
<Button
android:id="#+id/tab_video_main_btn_all"
style="#style/st_btn_top_header_gry"
android:layout_marginRight="2dp"
android:text="#string/st_tab_main_btn_all" />
<Button
android:id="#+id/tab_video_main_btn_my_videos"
style="#style/st_btn_top_header_gry"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:text="#string/st_tab_video_main_btn_my_videos"
android:visibility="visible" />
<Button
android:id="#+id/tab_video_main_btn_saved"
style="#style/st_btn_top_header_gry"
android:layout_marginLeft="2dp"
android:text="#string/st_tab_main_btn_saved" />
</LinearLayout>
<View style="#style/st_single_black_line" />
<TableLayout
android:id="#+id/video_search_holder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/background_header_small"
android:focusableInTouchMode="false"
android:gravity="left"
android:stretchColumns="0"
android:visibility="gone" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_margin="#dimen/margin_basic_very_large"
android:background="#drawable/audio_search_bg"
android:gravity="left|center_vertical"
android:paddingLeft="#dimen/padding_basic_2dp"
android:paddingRight="#dimen/padding_basic_2dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" >
<ImageButton
android:id="#+id/video_btn_search_clear"
style="#style/st_search_ui_ic_search"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:src="#drawable/ic_clear_search"
android:visibility="gone" />
<ImageButton
android:id="#+id/video_btn_search"
style="#style/st_search_ui_ic_search"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_search" />
<EditText
android:id="#+id/video_search_edit_text"
style="#style/st_search_ui_search_bar"
android:layout_toLeftOf="#id/video_btn_search_clear"
android:layout_toRightOf="#id/video_btn_search"
android:focusable="false"
android:focusableInTouchMode="false"
android:hint="#string/hint_search_by_video_title_or_description"
android:imeOptions="actionDone"
android:singleLine="true"
android:windowSoftInputMode="stateVisible|adjustResize" />
</RelativeLayout>
</TableRow>
</TableLayout>
<ListView
android:id="#+id/no_more_text_list"
style="#style/st_no_more_text_list"
android:visibility="gone" />
<ListView
android:id="#+id/video_chanel_list"
style="#style/st_comman_data_list" />
<View
android:id="#+id/invisible"
android:layout_width="match_parent"
android:layout_height="1dp" />
Solutions which i have tried:
set height as "match_parent"
add a view under the list view and make it invisible
set footer divider as enabled (which is true by default)
Someone have any ides why it is behaving differently?

Android custom dialog linearlayout size same as dialogs bg image

I am creating a custom dialog as:
Dialog myDialog = new Dialog(context, R.style.Theme_Levels);
myDialog.setContentView(R.layout.levelselector);
myDialog.show();
Style used:
<style name="Theme.Levels" parent="#android:style/Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">#drawable/dlgbg</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Layout xml file:
<LinearLayout android:id="#+id/LevelSelector"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_gravity="bottom|center_horizontal"
android:paddingBottom="50dip"
>
<Button android:text="Easy"
android:id="#+id/btn_Easy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
I want the button to appear at bottom center of the dialog (50dip padding from bottom) but it appears at top left of the Dialog.
Thats because LinearLayout does not know the width/height of the dialog, which is the size of the background image I have used in style xml file.
Question: How do I know the width height of the dialog so that LinearLayout is of the same size as the Dialog size?
Here is how you can do this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LevelSelector"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
android:paddingBottom="50dip" >
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button android:text="Easy"
android:id="#+id/btn_Easy"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Change android:layout_gravity="bottom|center_horizontal" to android:gravity="bottom|center_horizontal".
android:layout_gravity is gravity of the layout itself w.r.t. its parent. android:gravity applies to its contents.
i had the same problem in my case i ended up using a RelativeLayout
here it is.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/body" android:layout_margin="20dip"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/dialog_bg"
>
<TextView android:id="#+id/message"
android:layout_alignParentTop="true"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_margin="10dip"
android:inputType="textMultiLine"
android:textColor="#color/table_text"
android:textScaleX=".95" android:textStyle="bold"
/>
<TextView android:id="#+id/dummy" android:layout_below="#id/message"
android:layout_width="fill_parent" android:layout_height="60dip"
android:visibility="invisible"
/>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dip" android:layout_below="#id/message"
android:layout_centerHorizontal="true" android:orientation="horizontal"
>
<ImageButton android:id="#+id/ok"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/button_alert" android:src="#drawable/btn_yes"
android:visibility="gone" android:layout_weight=".5"
/>
<ImageButton android:id="#+id/cancel"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/button_alert" android:src="#drawable/btn_no"
android:visibility="gone" android:layout_weight=".5"
/>
</LinearLayout>
</RelativeLayout>
Ok, I have found a way, not a clean way but works.
You need to add background in style.xml file
<item name="android:windowBackground">#drawable/levelselectbg</item>
AND also in you linearlayout:
android:background="#drawable/levelselectbg"
The first background is required to keep the dialog borderless (which I have specified in my style.xml in my question) and the linearlayout background is required to give size to the layout, now it knows its dimensions and places the button at bottom center with padding.
Hope this helps someone, if a better solution is available please share.

Categories

Resources