Android fullscreen dialog - android

I am following https://blog.alexanderschaefer.io/android-material-full-screen-fragment-dialog to make a full screen dialog.
full_screen_dialog_layout
<?xml version="1.0" encoding="utf-8"?>
<android.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:paddingEnd="16dp"
android:paddingStart="6dp"
app:contentInsetStartWithNavigation="0dp"
app:navigationIcon="#drawable/ic_close_white_24dp"
android:paddingRight="16dp"
android:paddingLeft="6dp" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Hello I am a dialog!" />
</FrameLayout>
</android.coordinatorlayout.widget.CoordinatorLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.FullScreenDialog" parent="Theme.MaterialComponents.Light.Dialog">
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">#android:color/white</item>
<item name="actionMenuTextColor">#color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
FullScreenDialog.java
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.darekeapp.R;
public class FullScreenDialog extends DialogFragment {
private Toolbar toolbar;
public static FullScreenDialog display(FragmentManager fragmentManager) {
FullScreenDialog fullScreenDialog = new FullScreenDialog();
fullScreenDialog.show(fragmentManager, "example_dialog");
return fullScreenDialog;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.AppTheme_FullScreenDialog);
}
#Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.full_screen_dialog_layout,
container);
toolbar = view.findViewById(R.id.toolbar);
return view;
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FullScreenDialog.this.dismiss();
}
});
toolbar.setTitle("Some Title");
toolbar.inflateMenu(R.menu.full_screen_dialog_menu);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
FullScreenDialog.this.dismiss();
return true;
}
});
}
}
Home.java
...
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
FullScreenDialog.display(getSupportFragmentManager());
}
});
...
popup_add_shift_log.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="#+id/company_name_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/company_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_edt"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/company_name"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.SwitchCompat
android:id="#+id/worked_for_agent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:checked="true"
android:text="#string/worked_for_agent"
android:textSize="18sp"
android:textOn="#string/yes"
android:textOff="#string/no"
android:layout_below="#id/company_name_text_input_layout" />
<android.support.design.widget.TextInputLayout
android:id="#+id/agent_name_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/worked_for_agent"
android:layout_marginTop="10dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/agent_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_edt"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/agent_name"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatTextView
android:id="#+id/shift_start_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/agent_name_text_input_layout"
android:text="#string/shift_start"
android:textSize="18sp"
android:textColor="#android:color/black"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
android:id="#+id/shift_start_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
app:picker_curved="true"
app:picker_cyclic="true"
android:layout_below="#id/shift_start_question"
app:picker_visibleItemCount="7" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/shift_end_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/shift_start_time"
android:text="#string/shift_end"
android:textSize="18sp"
android:textColor="#android:color/black"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
android:id="#+id/shift_end_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
app:picker_curved="true"
app:picker_cyclic="true"
android:layout_below="#id/shift_end_question"
app:picker_visibleItemCount="7" />
<android.support.v7.widget.SwitchCompat
android:id="#+id/break_taken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:checked="true"
android:text="#string/break_taken"
android:textSize="18sp"
android:textOn="#string/yes"
android:textOff="#string/no"
android:layout_below="#id/shift_end_time" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/break_start_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/break_taken"
android:text="#string/break_start_time"
android:textSize="18sp"
android:textColor="#android:color/black"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
android:id="#+id/break_start_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
app:picker_curved="true"
app:picker_cyclic="true"
android:layout_below="#id/break_start_text"
app:picker_visibleItemCount="7" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/break_end_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/break_start_time"
android:text="#string/break_end_time"
android:textSize="18sp"
android:textColor="#android:color/black"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp" />
<com.github.florent37.singledateandtimepicker.SingleDateAndTimePicker
android:id="#+id/break_end_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
app:picker_curved="true"
app:picker_cyclic="true"
android:layout_below="#id/break_end_text"
app:picker_visibleItemCount="7" />
<android.support.v7.widget.SwitchCompat
android:id="#+id/transport_job"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:checked="true"
android:text="#string/transport_job"
android:textSize="18sp"
android:textOn="#string/yes"
android:textOff="#string/no"
android:layout_below="#id/break_end_time" />
<android.support.design.widget.TextInputLayout
android:id="#+id/transport_company_name_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/transport_job"
android:layout_marginTop="10dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/transport_company_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_edt"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/transport_company_name"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/vehicle_registration_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/transport_company_name_text_input_layout"
android:layout_marginTop="10dp">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/registration_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/round_edt"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/vehicle_registration"
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
</ScrollView>
I am trying to make the full screen dialog be displayed when the FAB (floating action button) is clicked. I want to set the view as the popup_add_shift_log. The app keeps crashing with various types of error, anything you can see I am doing wrong in the code

Pass dialog object to this Method.
public void resizeDialogToFullscreen(Dialog dialog) {
if (dialog != null && dialog.getWindow() != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}

Related

My application does not detect white color

I have a problem,but no one could help me.the problem is:
I have detail activity for show details of my product.
this activity has a toolbar(relative layout) with white background color.
everything is good and no problem but when I come from a fragment to this detail activity my toolbar color turn to blue!
I try to check what is the reason, and I finally detect my application does not know the white color!! if I use the #ffffff (hardcode or get from resource) my toolbar turn to blue but if I use any other color, it's okay even #fffffe
it is my style:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:fontFamily">#font/font</item>
<item name="fontFamily">#font/font</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
detailactivity code:
public class DetailActivity extends AppCompatActivity {
DetailViewModel detailViewModel = new DetailViewModel();
CompositeDisposable compositeDisposable = new CompositeDisposable();
String id,title;
TextView txtTitle, txtName, txtColor, txtguarantee, txtPrice, txtPoints, txtMore, txtDescription;
ImageView imgImage, imgShare, imgFav, imgCart, imgMore, imgBack;
RecyclerView recyclerView;
CardView properties;
CardView comments;
RatingBar ratingBar;
Button btnAddToBasket;
List<RatingModel> ratingModels;
NestedScrollView nestedScrollView;
Thread thread;
RelativeLayout toolbar;
int toolbarMergeColor, drawableMergeColor;
TextView txtToolbarTitle;
float ratio;
int startHeight;
int toolbarTitleYPosition = -1;
String imageUrl;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
setupViews();
getIntentId();
txtToolbarTitle.setTranslationY(150);
// observeForDetail();
}
private void getIntentId() {
id = getIntent().getExtras().getString("id");
}
private void setupViews() {
txtToolbarTitle = findViewById(R.id.txt_detail_toolbarTitle);
imgImage = findViewById(R.id.img_detail_image);
toolbar = findViewById(R.id.rel_detail_toolbar);
ratingModels = new ArrayList<>();
txtDescription = findViewById(R.id.txt_detail_description);
imgShare = findViewById(R.id.img_detail_share);
imgFav = findViewById(R.id.img_detail_favorite);
imgBack = findViewById(R.id.img_detail_back);
imgMore = findViewById(R.id.img_detail_more);
imgMore.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
PopupMenu popupMenu=new PopupMenu(DetailActivity.this,imgMore);
popupMenu.getMenuInflater().inflate(R.menu.detail_more_menu,popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem menuItem) {
if(menuItem.getItemId()==R.id.action_more_chart){
Intent intent=new Intent(getApplicationContext(), ChartActivity.class);
intent.putExtra("id",id);
intent.putExtra("title",title);
startActivity(intent);
}else{
Intent intent=new Intent(getApplicationContext(), CompareActivity.class);
intent.putExtra("image_url",imageUrl);
startActivity(intent);
}
return true;
}
});
popupMenu.show();
}
});
imgCart = findViewById(R.id.img_detail_cart);
txtTitle = findViewById(R.id.txt_detail_title);
txtName = findViewById(R.id.txt_detail_name);
txtColor = findViewById(R.id.txt_detail_color);
txtguarantee = findViewById(R.id.txt_detail_guarantee);
txtPrice = findViewById(R.id.txt_detail_price);
txtPoints = findViewById(R.id.txt_detail_points);
txtMore = findViewById(R.id.txt_detail_more);
txtMore.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (txtMore.getText().toString().equals("ادامه مطلب")) {
startHeight = txtDescription.getHeight();
txtDescription.setMaxLines(Integer.MAX_VALUE);
int widthSpec = View.MeasureSpec.makeMeasureSpec(txtDescription.getWidth(), View.MeasureSpec.EXACTLY);
int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
txtDescription.measure(widthSpec, heightSpec);
int targetHeight = txtDescription.getMeasuredHeight();
final int heightSpan = targetHeight - startHeight;
txtDescription.getLayoutParams().height = startHeight;
txtDescription.setLayoutParams(txtDescription.getLayoutParams());
Animation animation = new Animation() {
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
txtDescription.getLayoutParams().height = (int) (startHeight + heightSpan * interpolatedTime);
txtDescription.setLayoutParams(txtDescription.getLayoutParams());
}
};
animation.setDuration(300);
txtDescription.startAnimation(animation);
txtMore.setText("بستن");
} else {
startHeight = txtDescription.getHeight();
txtDescription.setMaxLines(8);
int widthSpec = View.MeasureSpec.makeMeasureSpec(txtDescription.getWidth(), View.MeasureSpec.EXACTLY);
int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
txtDescription.measure(widthSpec, heightSpec);
int targetHeight = txtDescription.getMeasuredHeight();
final int heightSpan = targetHeight - startHeight;
txtDescription.getLayoutParams().height = startHeight;
txtDescription.setLayoutParams(txtDescription.getLayoutParams());
Animation animation = new Animation() {
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
txtDescription.getLayoutParams().height = (int) (startHeight + heightSpan * interpolatedTime);
txtDescription.setLayoutParams(txtDescription.getLayoutParams());
}
};
animation.setDuration(300);
txtDescription.startAnimation(animation);
txtMore.setText("ادامه مطلب");
}
}
});
properties = findViewById(R.id.card_detail_properties);
properties.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DetailActivity.this, PropertiesActivity.class);
intent.putExtra("title", title);
startActivity(intent);
}
});
comments = findViewById(R.id.card_detail_comments);
comments.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), CommentActivity.class);
intent.putExtra("id",id);
intent.putExtra("name",txtName.getText().toString());
startActivity(intent);
}
});
btnAddToBasket = findViewById(R.id.btn_detail_addToBasket);
recyclerView = findViewById(R.id.rv_detail_points);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
ratingBar = findViewById(R.id.rating_detail);
}
#Override
protected void onDestroy() {
compositeDisposable.dispose();
super.onDestroy();
}
}
xml codes:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#color/gray200"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Detail.DetailActivity">
<RelativeLayout
android:id="#+id/rel_detail_toolbar"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<ImageView
android:layout_centerVertical="true"
android:layout_margin="8dp"
android:id="#+id/img_detail_back"
android:layout_alignParentRight="true"
app:srcCompat="#drawable/ic_arrow_back_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_centerVertical="true"
android:layout_margin="8dp"
app:srcCompat="#drawable/ic_more_vert_black_24dp"
android:id="#+id/img_detail_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_centerVertical="true"
app:srcCompat="#drawable/ic_shopping_cart_black_24dp"
android:layout_toRightOf="#id/img_detail_more"
android:id="#+id/img_detail_cart"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_alignParentBottom="true"
android:textColor="#color/colorWhite"
android:text="test test"
android:layout_marginRight="8dp"
android:layout_toLeftOf="#id/img_detail_back"
android:id="#+id/txt_detail_toolbarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScroll_detail"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:background="#ffffff"
android:id="#+id/img_detail_image"
android:layout_width="match_parent"
android:layout_height="200dp" />
<android.support.v7.widget.CardView
app:cardBackgroundColor="#color/gray100"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:paddingBottom="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/img_detail_share"
android:layout_margin="8dp"
app:srcCompat="#drawable/ic_share_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_margin="8dp"
app:srcCompat="#drawable/ic_favorite_black_24dp"
android:layout_toRightOf="#+id/img_detail_share"
android:id="#+id/img_detail_favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:ellipsize="end"
android:layout_below="#id/img_detail_share"
android:maxLines="1"
android:minLines="1"
android:textColor="#color/colorBlack"
android:layout_marginRight="8dp"
android:layout_alignParentRight="true"
tools:text="هارد اکسترنال سیلیکن پاور 1 ترا بایت"
android:id="#+id/txt_detail_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginRight="8dp"
android:layout_alignParentRight="true"
tools:text="هارد اکسترنال سیلیکن پاور 1 ترا بایت"
android:textSize="12sp"
android:id="#+id/txt_detail_name"
android:layout_width="wrap_content"
android:layout_below="#id/txt_detail_title"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:background="#color/gray200"
android:gravity="center"
android:padding="16dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_marginRight="4dp"
android:foreground="?android:selectableItemBackground"
android:layout_width="0dp"
android:id="#+id/card_detail_comments"
android:layout_weight="0.5"
android:layout_height="wrap_content">
<LinearLayout
android:gravity="center"
android:padding="8dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#color/gray700"
android:layout_marginRight="8dp"
android:text="نظرات کاربران"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
app:srcCompat="#drawable/ic_comment_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_marginLeft="4dp"
android:foreground="?android:selectableItemBackground"
android:layout_weight="0.5"
android:id="#+id/card_detail_properties"
android:layout_width="0dp"
android:layout_height="wrap_content">
<LinearLayout
android:gravity="center"
android:padding="8dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#color/gray700"
android:layout_marginRight="8dp"
android:text="مشخصات"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
app:srcCompat="#drawable/ic_comment_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.v7.widget.CardView
app:cardElevation="4dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_marginRight="8dp"
android:textSize="16sp"
android:layout_gravity="right"
android:textColor="#color/colorBlack"
android:text="رنگ"
android:id="#+id/txt_detail_colorTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginRight="8dp"
android:layout_gravity="right"
tools:text="مشکی"
android:id="#+id/txt_detail_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_margin="8dp"
android:layout_gravity="right"
tools:text="گارانتی سه ساله ۀوا"
android:id="#+id/txt_detail_guarantee"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:background="#color/gray300"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<TextView
android:textColor="#color/red"
android:layout_margin="8dp"
android:layout_gravity="right"
android:text="فروش توسط دیجی کالا"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_margin="8dp"
android:layout_gravity="right"
android:text="آماده ارسال از انبار دیجی کالا"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:background="#color/gray300"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<TextView
android:id="#+id/txt_detail_price"
android:layout_margin="8dp"
android:textColor="#color/green"
tools:text="1230000 تومان"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btn_detail_addToBasket"
android:layout_margin="8dp"
android:textColor="#color/colorWhite"
android:text="افزودن به سبد خرید"
android:background="#drawable/shape_btn_add_to_basket"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:drawableLeft="#drawable/ic_keyboard_arrow_left_black_24dp"
android:drawablePadding="8dp"
android:drawableRight="#drawable/ic_account_balance_black_24dp"
android:layout_gravity="center"
android:text="8 فروشنده و گارانتی برای این کالا وجود دارد"
android:textColor="#color/colorAccent"
android:layout_width="wrap_content"
android:layout_marginBottom="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
app:cardElevation="4dp"
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:maxLines="6"
android:ellipsize="end"
android:padding="16dp"
android:textColor="#color/colorBlack"
tools:text="محصولی با دوام و با کیفیت عالی همراه با ضمانت نامه"
android:id="#+id/txt_detail_description"
android:layout_width="match_parent"
android:layout_height="170dp" />
<View
android:background="#color/gray200"
android:layout_width="match_parent"
android:layout_height="1dp"/>
<TextView
android:id="#+id/txt_detail_more"
android:padding="8dp"
android:text="ادامه مطلب"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
app:cardElevation="4dp"
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RatingBar
style="?android:attr/ratingBarStyleSmall"
android:layout_centerHorizontal="true"
android:progressTint="#color/red"
android:rating="3.5"
android:id="#+id/rating_detail"
android:numStars="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/txt_detail_points"
android:layout_marginLeft="8dp"
android:layout_toRightOf="#id/rating_detail"
tools:text="3.5 از 5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:layout_margin="8dp"
android:layout_below="#id/rating_detail"
android:id="#+id/rv_detail_points"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
What is activity theme in style , if you do not set noActionBar theme android put default toolbar on your relative layout and you cant see it
So define your styles like this
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/activityBackground</item>
<item name="colorPrimaryDark">#color/greyTextColor</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and set AppTheme.NoActionBar bar theme to your activity in AndroidManifest file
Or Use
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
Try using -
android:background="#android:color/white"
You may wanna try that; define a new color to the "colors.xml" and use it as background.
Update
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
You should change your #color/colorPrimary and #color/colorPrimaryDark with the colors you want. Define them in colors and assign them instead of those two above. It must be fixed. Good Luck!
You have two choice
1) you can set your toolbar color in your detail activity onCreate
toolbar.setBackgroundColor(Color.WHITE);
check this may this works or
2) in color.xml set white color and get the reference from there
"< color name="colorTransWhite">#ffffffff< /color>" (remove extra spaces)
check any of one and let me know if not work.

How to start shared element transition between 2 activity?

I just learn about Shared Element in Android and I have one image which one of them in ActivitySplashScreen and one other is into Toolbar and I want to use shared element to move this image from ActivitySplashScreen to ActivityMain
after some search and try to implement that simple way to make this feature don't work on my code, for example:
style.xml:
<style name="AppTheme" parent="BaseTheme">
<item name="android:windowContentTransitions">true</item>
</style>
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
...
</style>
ActivitySplashScreen.java:
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
ButterKnife.bind(this);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(ActivitySplashScreen.this, MainActivity.class);
ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(ActivitySplashScreen.this,
app_logo,
ViewCompat.getTransitionName(app_logo));
startActivity(intent, options.toBundle());
finish();
}
}, 3000);
}
ActivityMain.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
supportPostponeEnterTransition();
}
and ImageView widget on my ActivitySplashScreen and ActivityMain xml layout:
<ImageView
android:id="#+id/instagram_add_story"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:src="#drawable/img_wizard_1"
android:transitionName="app_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="VectorDrawableCompat" />
this code is not working as well and I'm not sure what exactly problem on that
UPDATED
ActivitySplashScreen 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">
<LinearLayout
android:id="#+id/alachiq_header_animation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#drawable/instagram_animation_gradient_list"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="40dp">
<ImageView
android:id="#+id/app_logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:transitionName="app_logo"
android:tint="#android:color/white"
app:srcCompat="#drawable/img_wizard_1" />
<TextView
android:id="#+id/title"
style="#style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:fontFamily="#font/iran_sans_bold"
android:gravity="center"
android:text="#string/app_name"
android:textColor="#color/mdtp_white" />
<TextView
style="#style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/iran_sans_light"
android:gravity="center"
android:textColor="#color/mdtp_white" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:slidingLayer="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/grey_5"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="5dp"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/Toolbar.Light">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/activityTitle"
style="#style/Base.TextAppearance.AppCompat.Caption"
android:layout_width="90dp"
android:layout_height="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:fontFamily="#font/iran_sans_bold"
android:gravity="center|right"
android:text="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/application_logo"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/application_logo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:scaleType="centerCrop"
android:layout_marginBottom="8dp"
android:src="#drawable/ic_app_logo"
android:transitionName="app_logo"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/drawerMenu"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="VectorDrawableCompat" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
I can use in this way here is my solution according to your scenario.
Style:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
Splash.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">
<LinearLayout
android:id="#+id/alachiq_header_animation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#drawable/ic_launcher_background"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="40dp">
<ImageView
android:id="#+id/app_logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:tint="#android:color/black"
app:srcCompat="#android:drawable/ic_dialog_email" />
<TextView
android:id="#+id/title"
style="#style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:text="#string/app_name"
android:textColor="#android:color/background_dark" />
<TextView
style="#style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:fontFamily="sans-serif"
android:textColor="#android:color/background_dark" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Splash.Java
public class SplashActivity extends AppCompatActivity {
#BindView(R.id.app_logo)
ImageView app_logo;
Activity mActivity;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ButterKnife.bind(this);
mActivity = this;
ViewCompat.setTransitionName(app_logo, "app_logo");
new Handler().postDelayed(new Runnable() {
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
#Override
public void run() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
intent.putExtra("transition_name", ViewCompat.getTransitionName(app_logo));
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(mActivity,app_logo,ViewCompat.getTransitionName(app_logo));
startActivity(intent, options.toBundle());
finish();
}
}, 3000);
}
}
MainActivity.XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:slidingLayer="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="5dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
app:contentInsetStartWithNavigation="0dp"
>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/activityTitle"
android:layout_width="90dp"
android:layout_height="30dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center|right"
android:text="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/application_logo"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginRight="8dp" />
<ImageView
android:id="#+id/application_logo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:scaleType="centerCrop"
android:layout_marginBottom="8dp"
android:tint="#android:color/black"
app:srcCompat="#android:drawable/ic_dialog_email"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
android:layout_marginRight="8dp" />
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
MainActivity.Java
public class MainActivity extends AppCompatActivity {
#BindView(R.id.toolbar)
Toolbar mToolbar;
Activity mActivity;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
mActivity = this;
setSupportActionBar(mToolbar);
ActivityCompat.postponeEnterTransition(this);
ImageView application_logo = (ImageView) mToolbar.findViewById(R.id.application_logo);
if (getIntent() != null) {
Bundle extras = getIntent().getExtras();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
String imageTransitionName = extras.getString("transition_name");
application_logo.setTransitionName(imageTransitionName);
ActivityCompat.startPostponedEnterTransition(mActivity);
}
}
}
}
Here is the Sample code for SharedElementTransition according to your scenario. Whenever you use some kind of style always write in style file then use it.
Note: import android.support.v7.widget.Toolbar; for ToolBar in Java file. This is working fine.

RelativeLayout in DialogFragment - MarginBottom is ignored

So basically, I have this DialogFragment that is fullscreen and has a button over a progressbar (if you click the button, it disappears and the progressbar is visible). I initially had the xml in an activity and everything worked as expected there, but now I want to refactor it to a fullscreen dialogfragment.
Problem is, the button that was ontop of the progressbar is now aligned to the bottom of the parentLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/activity_gps_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_setsensor"
tools:ignore="MissingPrefix"
>
<ImageView
android:layout_width="90dp"
android:layout_height="38dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:orientation="vertical"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_location"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="17dp"
android:gravity="center_horizontal"
android:text="#string/promptGpsPermissionBody"
style="#style/fullscreenText"
/>
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btnActivateGps"
android:layout_alignTop="#+id/btnActivateGps"
style="?android:attr/progressBarStyle"
/>
<Button
android:id="#+id/btnActivateGps"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="71dp"
android:layout_marginLeft="63dp"
android:layout_marginRight="63dp"
android:background="#color/white"
android:enabled="true"
android:visibility="visible"
/>
</RelativeLayout>
What's especially weird is that the progressbar is aligned to the button, but it's still located at the same position as before
here is the java-code
public class GpsSensorDialog extends DialogFragment {
#NonNull #Override public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.activity_gps_sensor, null);
builder.setView(view);
Dialog dialog = builder.create();
if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow()
.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
return dialog;
}
#Override public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_TITLE, R.style.CustomDialog);
}
public static GpsSensorDialog newInstance() {
Bundle args = new Bundle();
GpsSensorDialog fragment = new GpsSensorDialog();
fragment.setArguments(args);
return fragment;
}
#Override public void onStart() {
super.onStart();
getDialog().getWindow()
.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
}
and the Style I set in onCreate
<style name="CustomDialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
Try this layout. Also, change your drawables, style and strings accordingly.
<RelativeLayout 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:id="#+id/activity_gps_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#mipmap/ic_launcher"
tools:ignore="MissingPrefix">
<ImageView
android:layout_width="90dp"
android:layout_height="38dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="17dp"
android:gravity="center_horizontal"
android:text="obsdas" />
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/btnActivateGps" />
<Button
android:id="#+id/btnActivateGps"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="71dp"
android:layout_marginLeft="63dp"
android:layout_marginRight="63dp"
android:background="#android:color/white"
android:enabled="true"
android:visibility="visible" />
</RelativeLayout>

DialogFragment with transparent background

I'm trying to create a fullscreen (but status bar has to still be visible) Dialog with custom transparent (same as this answer https://stackoverflow.com/a/29482234), but my background is not transparent.
I've wasted 2 days trying all solution, but it just won't work. My goal is to show a dialog with custom dim color (instead of default black). The answer above looked like what I needed but I can't get it to work. Any suggestions?
My code:
<style name="CustomDialogTheme2" parent="#android:style/Theme.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
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"
android:background="#AAFFFFFF">
<RelativeLayout
android:id="#+id/dialog_root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#CCFF0000"
android:padding="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</RelativeLayout>
</FrameLayout>
DialogFragment:
public class TestDialogFrag extends DialogFragment {
public static TestDialogFrag newInstance() {
Bundle args = new Bundle();
TestDialogFrag fragment = new TestDialogFrag();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomDialogTheme2);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.test_dialog_frag, container, false);
return view;
}
}
Try the below, It will help you.
Layout File
<?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:layout_gravity="center"
android:gravity="center">
<LinearLayout
android:layout_width="260dp"
android:layout_height="wrap_content"
android:background="#color/colorWhite"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_gravity="center"
android:gravity="center">
<ImageView
android:id="#+id/dialog_universal_info_image"
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#ff0000"
android:contentDescription="Imagg"
android:scaleType="centerCrop" />
<View
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#4cbdbcbc" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/app_name"
android:textColor="#android:color/white"
android:textAppearance="?android:textAppearanceLarge" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="22dp"
android:paddingLeft="26dp"
android:paddingRight="26dp"
android:paddingTop="22dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/dialog_info_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="heare"
android:textColor="#android:color/holo_green_dark"
android:textAppearance="?android:textAppearanceLarge" />
<TextView
android:id="#+id/dialog_info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="4"
android:text="Content is here"
android:textColor="#android:color/holo_green_dark" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
android:background="#android:color/holo_blue_dark" />
<TextView
android:id="#+id/dialog_info_ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="OK"
android:textColor="#android:color/holo_green_dark"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
Java File
public class DialogUtilsInfo {
public Activity mDialogUniversalInfoActivity;
private Dialog mDialog;
private TextView mDiaappicon_48KButton;
public DialogUtilsInfo(Activity mDialogUniversalActivity) {
this.mDialogUniversalInfoActivity = mDialogUniversalActivity;
}
public void showDialog(String content) {
if (mDialog == null) {
mDialog = new Dialog(mDialogUniversalInfoActivity, R.style.CustomDialogTheme);
}
mDialog.setContentView(R.layout.dialog_info);
mDialog.setCancelable(true);
mDialog.show();
mDiaappicon_48KButton = (TextView) mDialog.findViewById(R.id.dialog_info_ok);
initDialogButtons1();
}
private void initDialogButtons1() {
mDiaappicon_48KButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
mDialog.dismiss();
}
});
}
public void dismissDialog() {
mDialog.dismiss();
}
}

Change background color of header in DialogFragment android

I have DialogFragment, which show some information. It's work nice, but I need different header, I need white Title color text and blue background of the header.
This is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_teacher"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/teacher"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_teacher"
android:layout_toRightOf="#+id/icon_teacher"
android:layout_toEndOf="#+id/icon_teacher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/teacher_name"
android:layout_below="#+id/teacher"
android:layout_alignLeft="#+id/teacher"
android:layout_alignStart="#+id/teacher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_time"
android:layout_below="#+id/icon_teacher"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/time"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_time"
android:layout_toRightOf="#+id/icon_time"
android:layout_toEndOf="#+id/icon_time" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/time_name"
android:layout_below="#+id/time"
android:layout_alignLeft="#+id/time"
android:layout_alignStart="#+id/time" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_place"
android:layout_below="#+id/icon_time"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/place"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_place"
android:layout_toRightOf="#+id/icon_place"
android:layout_toEndOf="#+id/icon_place" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/place_name"
android:layout_below="#+id/place"
android:layout_alignLeft="#+id/place"
android:layout_alignStart="#+id/place" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:id="#+id/icon_home"
android:layout_below="#+id/icon_place"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/teacher"
android:id="#+id/home"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/icon_home"
android:layout_toRightOf="#+id/icon_home"
android:layout_toEndOf="#+id/icon_home" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name_of_teacher"
android:textColor="#android:color/black"
android:textSize="16dp"
android:id="#+id/place_home"
android:layout_below="#+id/home"
android:layout_alignLeft="#+id/home"
android:layout_alignStart="#+id/home" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/divider1"
android:layout_below="#+id/icon_home"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/divider1"
android:layout_marginTop="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher"
android:layout_marginLeft="10dp"
android:id="#+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/alert"
android:id="#+id/alert"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And my DialogFragment, but i think it won't be helpful so much:
public class LessonDialogFragment extends DialogFragment {
View view;
String title;
public LessonDialogFragment(String title) {
this.title = title;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.detail_dialog_fragment, container, false);
getDialog().setTitle(title);
return view;
}
}
I don't know how change it, maybe you can help me.
for custom layout:
https://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout
AlertDialog dialog = builder.show();
// Set title divider color
int titleDividerId = getResources().getIdentifier("titleDivider", "id", "android");
View titleDivider = dialog.findViewById(titleDividerId);
if (titleDivider != null)
titleDivider.setBackgroundColor(getResources().getColor(android.R.color.holo_purple));
Customising the background of the header is slightly more complex... You need to define in your theme an alertDialogStyle defining how you draw each area of the dialog. For example:
<style name="Theme.Yours" parent="#android:style/Theme.Holo">
...
<item name="android:alertDialogStyle">#style/AlertDialog_Yours</item>
</style>
<style name="AlertDialog_Yours">
<item name="android:fullDark">...</item>
<item name="android:topDark">...</item>
<item name="android:centerDark">...</item>
<item name="android:bottomDark">...</item>
<item name="android:fullBright">...</item>
<item name="android:topBright">...</item>
<item name="android:centerBright">...</item>
<item name="android:bottomBright">...</item>
<item name="android:bottomMedium">...</item>
<item name="android:centerMedium">...</item>
</style>

Categories

Resources