All my modal BottomSheets have a white background above them and are not transparent as intended.
I tried opening the view via a separate Fragment like this:
ContextMenuPlaylistFragment contextMenuPlaylistFragment = new ContextMenuPlaylistFragment();
contextMenuPlaylistFragment.show(fragmentManager,"contextmenu playlists");
and like that:
View modelBottomSheet = LayoutInflater.from(mContext).inflate(R.layout.context_menu_playlist, null);
BottomSheetDialog dialog = new BottomSheetDialog(mContext);
dialog.setContentView(modelBottomSheet);
dialog.show();
This is my BottomSheetFragment:
public class ContextMenuPlaylistFragment extends BottomSheetDialogFragment {
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.context_menu_playlist, container, false);
}
}
And this is my BottomSheet:
<?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:background="#color/transparent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_playlist_search"
android:orientation="horizontal"
android:layout_marginBottom="15dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_search_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/search_playlist"
android:textSize="18sp"
android:layout_marginStart="10dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_playlist_rename"
android:orientation="horizontal"
android:layout_marginBottom="15dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_edit_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rename_playlist"
android:textSize="18sp"
android:layout_marginStart="10dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button_playlist_delete"
android:orientation="horizontal"
android:layout_marginBottom="15dp">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/ic_delete_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delete_playlist"
android:textSize="18sp"
android:layout_marginStart="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I put it in two LinearLayouts to try and make the background transparent.
I also tried it with one LinearLayout that doesn't change the background and has height "wrap_content"
Please check if you have set the android:background attribute in the "AppTheme" style to white. If so, delete it or set it to transparent will solve the problem.
Related
I am making a window to open an empty dialog and write comments.
The dialog initially has an empty item where i can write one comment.
Comments can be up to one line.
Pressing the Enter key dynamically creates an item that allows you to write the next comment.
I was wondering whether to use RecyclerView or addView() for this function.
Since this dialog was also opened from the recycler view item of the parent, it would be complicated when using RecyclerView again, so I used addView().
I don't know if this is the right choice.
This is because data management seems to be difficult because the created comment must be saved in the parent's recycler view item.
Anyway, using addView() does not add the view.
There is no such thing as an error, but it cannot be added.
What is the cause?
writeing_comment_item
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".fragment.WritingCommentDialogFragment">
<TextView
android:id="#+id/start_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" * "
android:textSize="15sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="15dp"
android:layout_marginRight="2dp"
android:layout_marginLeft="10dp"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/comment_edit" />
<EditText
android:id="#+id/comment_edit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginRight="10dp"
android:background="#null"
android:textSize="15sp"
android:inputType="text"
android:maxLines="1"
android:maxLength="22"
app:layout_constraintLeft_toRightOf="#+id/start_point"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
fragment_writing_comment_dialog
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".fragment.WritingCommentDialogFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="#+id/start_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" * "
android:textSize="15sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="15dp"
android:layout_marginRight="2dp"
android:layout_marginLeft="10dp" />
<EditText
android:id="#+id/comment_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginRight="10dp"
android:background="#null"
android:textSize="15sp"
android:inputType="text"
android:maxLines="1"
android:maxLength="22" />
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
WritingCommentDialogFragment.java
public class WritingCommentDialogFragment extends DialogFragment {
LinearLayout mContainer;
EditText editText;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_writing_comment_dialog, container, false);
editText = view.findViewById(R.id.comment_edit);
mContainer = view.findViewById(R.id.container);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override // IME actionNone (Enter Key)
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
View inflater1 = LayoutInflater.from(getContext()).inflate(R.layout.writing_comment_item, mContainer, false);
mContainer.addView(inflater1);
return true;
}
});
return view;
}
#NonNull
#Override
public Dialog onCreateDialog(#Nullable Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.setCanceledOnTouchOutside(false);
return dialog;
}
#Override
public void onResume() {
super.onResume();
setDialogSize();
}
private void setDialogSize() {
getDialog().getWindow().setLayout(1000, 1000);
}
}
your problem is that you added a horizontal LinearLayout and after you added an EditText with android: layout_width = "match_parent" that's why your Comment is added on your container view but is not visible because of the EditText.
if I understood correctly you must change
android: orientation = "horizontal" by android: orientation = "vertical" in your fragment_writing_comment_dialog
so that the commentary will be displayed above the EditText
And also you need to change the orientation on your Container LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".fragment.WritingCommentDialogFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="#+id/start_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" * "
android:textSize="15sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginTop="15dp"
android:layout_marginRight="2dp"
android:layout_marginLeft="10dp" />
<EditText
android:id="#+id/comment_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginRight="10dp"
android:background="#null"
android:textSize="15sp"
android:inputType="text"
android:maxLines="1"
android:maxLength="22" />
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I am trying to set my custom dialog fragment to use the full width of the screen. The one solution is to set LayoutParams on view. But they are not working.
Things I Tried
Changing parent Layout
using getLayoutParams().getClass() which returns null
Layout Validator shows correct layout so no prob here, here is my Layout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
style="#style/MaterialAlertDialog.MaterialComponents.Title.Text.CenterStacked"
android:id="#+id/ask_hint_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:id="#+id/puppy_vw"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<pl.droidsonroids.gif.GifImageView
android:layout_width="150dp"
android:layout_height="wrap_content"
android:src="#drawable/solving"
android:adjustViewBounds="true">
</pl.droidsonroids.gif.GifImageView>
<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/MaterialAlertDialog.MaterialComponents.Title.Text.CenterStacked"
android:text="#string/ad_confirm_text"/>
</LinearLayout>
<LinearLayout
android:layout_alignParentEnd="true"
android:layout_below="#id/puppy_vw"
android:id="#+id/ad_confm_btns"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:layout_centerInParent="true">
<com.google.android.material.button.MaterialButton
android:id="#+id/yes_hint"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:backgroundTint="#color/cardview_dark_background"
style="#style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:text="Yes">
</com.google.android.material.button.MaterialButton>
<!--
<com.google.android.material.button.MaterialButton
android:id="#+id/no_hint"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:backgroundTint="#color/cardview_dark_background"
style="#style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:text="No">
</com.google.android.material.button.MaterialButton>
-->
<com.google.android.material.button.MaterialButton
android:id="#+id/why_hint"
android:layout_margin="5dp"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/cardview_dark_background"
style="#style/Widget.MaterialComponents.Button.UnelevatedButton"
android:text="Why Ads?">
</com.google.android.material.button.MaterialButton>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</FrameLayout>
Here is my DialogFragment class
public class AdLoadFragment extends DialogFragment {
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
AskHintDialogBinding binding=AskHintDialogBinding.inflate(inflater,container,false);
View view=binding.getRoot();
return view;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
MyUtilsApp.showLog(String.valueOf(view.getClass()));
view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
}
}
I´d like to design a layout in XML and want to duplicate it dynamicly, depence on the size of a list. It has to be done in a fragment. Unfortunally I cannot find how to do it in fragments.
This ist the idea of the XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<FrameLayout
android:id="#+id/complete_map_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ICH bin die MAP!! Ich möchte ein Bild werden"
android:id="#+id/textView7"
android:layout_gravity="center_horizontal" />
<!-- Erstellung einzelner Räume -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="20dp"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:id="#+id/roomRow">
<!-- Bezeichnung Raum -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.10"
android:orientation="vertical"
android:id="#+id/roomNameOne"
android:background="#ff0000">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/roomName"
android:layout_gravity="center_vertical"
android:rotation="-90"
android:text="PLATZHALTER"/>
</LinearLayout>
<!-- Inhalt Raum -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.40"
android:orientation="horizontal"
android:id="#+id/WeaponNameOne">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/testWeapon"
android:layout_gravity="center_vertical"
android:text="WAFFE"
android:background="#00ff00"/>
</LinearLayout>
<!-- Inhalt Raum2 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.40"
android:orientation="horizontal"
android:id="#+id/weaponNameTwo"
android:background="#0000ff">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/testWeapon2"
android:layout_gravity="center_vertical"
android:text="WAFFE"/>
</LinearLayout>
<!-- Bezeichnung Raum2 -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.10"
android:rotation="90"
android:id="#+id/roomNameTwo"
android:background="#ff0000">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/roomName2"
android:layout_gravity="center_vertical"
android:text="PLATZHALTER"/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_gravity="right|bottom" />
</FrameLayout>
</ScrollView>
This is the java-code:
public class MapOverview extends Fragment {
Bundle extras;
View fragLayoutV;
Game game;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
fragLayoutV = inflater.inflate(R.layout.fragment_map, null);
extras = getActivity().getIntent().getExtras();
game = (Game) extras.get("GAME");
return fragLayoutV;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
FrameLayout frame = (FrameLayout)fragLayoutV.findViewById(R.id.complete_map_layout);
//LinearLayout roomInflator = (LinearLayout)frame.findViewById(R.id.roomRow);
Log.e("RAUM", game.getRooms().get(0).getName());
for(Room r:game.getRooms()){
frame.addView((LinearLayout)frame.findViewById(R.id.roomRow));
}
}
}
Of course I get an error by doing this. Can anybody help?
The aim is to have a picture like this:
http://i.stack.imgur.com/3DS73.png
Don´t matter about the colors ^^
You need to re-inflate your layout every time you want to add it. You can not add the same View multiple times.
Try something like this:
LayoutInflater inflater = LayoutInflater.from(this.getContext());
for (Room r : game.getRooms()) {
View view = inflater.inflate(R.layout.your_duplicate_layout, frame, false);
// Do whatever you want with view
frame.addView(view);
}
Where R.layout.your_duplicate_layout correspond to your current layout with id=roomRow.
I've created this class:
public class AlertDialogFragment extends DialogFragment {
...
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_alert, container);
...
My dialog_alert.xml layout file:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/dialog_background">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:paddingLeft="#dimen/keyline_4"
android:paddingRight="#dimen/keyline_4"
android:paddingTop="#dimen/keyline_4">
<TextView
android:id="#+id/title"
style="#style/DialogTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="20dp"
android:text="#string/visible_by"
android:visibility="gone"/>
<TextView
android:id="#+id/content"
style="#style/DialogContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vos données de connexion sont incorrectes." />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="#dimen/keyline_4"
android:paddingRight="#dimen/keyline_1"
android:paddingBottom="#dimen/keyline_1"
android:layout_gravity="right">
<TextView
android:id="#+id/negative_button"
style="#style/DialogButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/keyline_0"
android:text="negative"
android:visibility="gone" />
<TextView
android:id="#+id/positive_button"
style="#style/DialogButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="positive" />
</LinearLayout>
</LinearLayout>
And the result is:
I've defined "match_parent" attribute with the padding equal at 24dp (=#dimen/keyline_4).
Thanks for your help guys!
I am using DialogFragment to display a dialog.But the dialog was displayed with the title.When i used no title my dialog was not being displayed properly.
Dialog with title
Dialog without title
Xml
<?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:background="#drawable/share_background"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share"
android:textSize="25sp"
android:textColor="#fff"
android:id="#+id/textView"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button3" />
</LinearLayout>
</LinearLayout>
DialogFragment Code
public class ShareDialogFragment extends DialogFragment {
private View view;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.share_dialog, null, false);
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return view;
}
}
Why this is happening????
Try this:
<TextView
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Share"
android:textSize="25sp"
android:textColor="#fff"
android:id="#+id/textView"
android:layout_gravity="center_horizontal" />
Hope this helps.
Fix layout height and width of your parent linear layout to a fixed value.
Example:
android:layout_width="200dp"
android:layout_height="wrap_content"
Try this:
inflater.inflate(R.layout.share_dialog, container, false);