I intend to display a Dialog with a custom layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="#dimen/lef_margin"
android:layout_marginTop="#dimen/lef_margin"
android:background="#ffffff"
android:fitsSystemWindows="true" />
<ImageView
android:id="#+id/imgsocialauthclose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right|top"
android:background="#drawable/closexml" />
</FrameLayout>
Now, if I I set this layout to the dialog through, Dialog.setContentView(), I get something like below(please note that the concerned Dialog is the thine white box with a cross button in the middle and the not the one with all the social media options in the background):
Now, if I were to write this additional line in addition to the setContentView() call, I get a Dialog that extends to cover parent view:
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
If you observer the layout, you would notice that the MATCH_PARENT constraint has already been declared. Then, why do I need to do this additional line or,
Why doesn't the Dialog respect the MATCH_PARENT constraint properly by default?
I solved this once for a dialog fragment by adding this to onCreateDialog. This will make your dialog full screen. Then you can define margin/padding with transparent background to shape your dialog in any way you want.
Dialog dialog = new Dialog(getActivity() ,android.R.style.Theme_Holo_NoActionBar);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
then to show the dialog just use
MyDialogFragment fragment = new MyDialogFragment();
fragment.show(getChildFragmentManager(), "addPlaylistDialog");
Related
I want a splash screen to be shown before opening an activity. For that i create a splash screen. But my problem is i have multiple activity in my app for that right now i am using that single splash screen. So what's the correct way to do that either i have to add it to all activity one by one or can be done same at once, then how? what's the way for that?.
Elaborating my comment there, you are confused with the purpose of Splash Screen. As the name says, it should just appear for splash of a second in the beginning and disappear, for further feedback to user to show downloads you have to use ProgressBar
Here you can externalize the code for ProgressBar to have minimal codes.
progress_bar_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:background="#color/colorAccent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- Customize yoiur progress bar screen here-->
</RelativeLayout>
then include this layout wherever you want
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.android.myApp.MainActivity"
tools:showIn="#layout/app_bar_main">
<include
android:id="#+id/progress_bar"
android:visibility="gone"
layout="#layout/progress_bar_layout" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Then in your java class
private RelativeLayout progressBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//some code
progressBar = (RelativeLayout)findViewById(R.id.progress_bar);
//control parent instead of progress bar only
}
private void beginDownload(){
progressBar.setVisibility(View.VISIBLE);
//your download code
}
private void downloadComplete(){
progressBar.setVisibility(View.GONE);
//codes once download is completed
}
P.S. If your design specifically requires some different screen other
than rotating progress bar, then use same approach, just change the
progress_bar_layout.xml to reflect your design, everything else will
remain same. Hence No Concept Of Splash Screen For This Task, Just
Progress Bar.
include activity in dialog...activity include multi list view
please help
As I see, this is not an activity in a dialog. The Dialog itself has custom view which has title, edit text and list view.
Not sure what are u looking for....but you can create a CustomDialog like this:
custom_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="#+id/edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp" />
<ListView
android:id="#+id/list"
android:layout_width="match_parrent"
android:layout_height="wrap_content"/>
</RelativeLayout>
And in your activity create it like:
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title...");
I'm trying to dynamically set the text of a button that I'm inflating at runtime, but the text isn't being set.
I'm creating a custom Dialog for which I set SetContentView with a View that I inflate at runtime. The view contains a single Button, e.g:
var dialog = new SetUnsetDialog();
var view = View.Inflate(_context, Resource.Layout.view_set_unset_buttons, null);
view.FindViewById<Button>(Resource.Id.btnPartsetA).Text = _blockDescriptions["partseta"];
dialog.SetContentView(view);
dialog.SetTitle("Set/Unset " + _area);
dialog.Show();
The layout is defined as:
<?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="wrap_content"
android:orientation="vertical">
<!-- irrelevant stuff removed -->
<LinearLayout
android:id="#+id/linearLayoutSetUnsetButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<!-- irrelevant stuff removed -->
<Button
android:id="#+id/btnPartsetA"
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:drawableTop="#drawable/partset_a" />
<!-- irrelevant stuff removed -->
</LinearLayout>
</LinearLayout>
Why is the button text not being set? What do I need to do to set it?
UPDATE:
It turns out this is a non-issue. The content view gets reset later and overwrites the values that I set.
what about using the setText method instead of .Text?
I want the title dialog with the name of book. The problem is with the long title, it seems the default title dialog tries to trim the extra long text in order to fit the dialog width
So I came up with the solution that removing the default title by this code
setStyle(STYLE_NO_TITLE, 0);
Replace the default with a textview widget. This is my custom dialog xml
<?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" >
<TextView
android:id="#+id/dialog_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
However it just mess up the dialog layout
So could anyone me a better way to deal with that ? Thanks
You can use google to set custom view to a dialog
but don't forget to dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); :)
So in your DialogFragments onCreate you setStyle:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Theme_Dialog);
}
You then use your own very custom xml layout to create the dialog in oncreateview().
In my layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="#+id/user_pswd_new_root" android:scrollbars="vertical"
android:soundEffectsEnabled="true">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/ScrollViewLogin" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbarStyle="outsideInset" android:scrollbars="vertical|horizontal" android:visibility="visible">
<RelativeLayout android:layout_width="fill_parent" android:id="#+id/relativeLayout1" android:layout_height="fill_parent">
<ImageView android:background="#drawable/logo_login" android:layout_height="wrap_content" android:id="#+id/imageView1"
android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"
android:padding="0dp" android:layout_margin="0dp"/>
...............
</RelativeLayout>
</ScrollView>
</RelativeLayout>
With the above code, I set in a Dialog and things are shown proeprly, but there is lot of unwanted space above the image which unnecessarily increases the height of the dialog. See the results :
Any idea why the top space is occupied. And how do I get rid of it. Where am I going wrong ?
It's the title of the Dialog, which is empty because you didn't specify a title (but the view is still there). You have to remove it, for example like this:
class MyDialog extends Dialog {
#Override
protected void onCreate(Bundle savedInstanceState) {
// make sure to call requestWindowFeature before setContentView
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.my_dialog_layout);
// other initialization code
}
// ...
}
But that depends on whether you are using a simple Dialog or an AlertDialog. If this doesn't work for you, post your dialog-creation code (Java) and I'll update my answer to show how to remove the title in your case.