I've got the following code:
private void openDatePicker() {
MaterialDatePicker picker =
MaterialDatePicker.Builder.datePicker()
.setTitleText("Select date")
.setTheme(R.style.DatePickerTheme)
.setSelection(MaterialDatePicker.todayInUtcMilliseconds())
.build();
picker.show(getParentFragmentManager(),"tag");
picker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener() {
#Override
public void onPositiveButtonClick(Object selection) {
try {
mtnRecDate.setText(sdf.format(selection));
} catch (Exception e) {
FancyToast.makeText(getContext(),"Setting Date failed!",FancyToast.LENGTH_LONG,FancyToast.ERROR,false).show();
}
}
});
}
Style:
<!-- Picker styles and themes. -->
<style name="DatePickerTheme" parent="#style/ThemeOverlay.MaterialComponents.MaterialCalendar">
<item name="materialCalendarStyle">#style/Widget.MaterialComponents.MaterialCalendar</item>
<item name="materialCalendarFullscreenTheme">#style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen</item>
<item name="materialCalendarTheme">#style/Widget.MaterialComponents.MaterialCalendar.MonthNavigationButton</item>
<item name="materialCalendarMonthNavigationButton">#style/Widget.MaterialComponents.MaterialCalendar.MonthNavigationButton</item>
</style>
I'm trying to hide the year option:
It should look more like this:
How can I achieve this. I tried changing the style theme (see above) with no results unfourtantly.
You can check this documentation.
As mentioned google documentation code below can fulfill your intent:
<style name="Theme.App" parent="Theme.MaterialComponents.*">
...
<item name="materialCalendarTheme">#style/ThemeOverlay.App.DatePicker</item>
</style>
<style name="ThemeOverlay.App.DatePicker"
parent="#style/ThemeOverlay.MaterialComponents.MaterialCalendar">
<item name="colorPrimary">#color/shrine_pink_100</item>
<item name="colorOnPrimary">#color/shrine_pink_900</item>
<item name="shapeAppearanceSmallComponent">#style/ShapeAppearance.App.SmallComponent</item>
<item name="shapeAppearanceMediumComponent">#style/ShapeAppearance.App.MediumComponent</item>
<!-- Customize text field of the text input mode. -->
<item name="textInputStyle">#style/Widget.App.TextInputLayout</item>
So you should change your style from MaterialCalendar to DatePicker.
Related
I'm trying to change the color of the AlertDialog with likely all solutions defined for this issue in stackoverflow and it still doesn't work.
This is the code I'm using to try to achieve that:
val vacationDialog = AlertDialog.Builder(fragment.context,R.style.DialogTheme)
val factory = LayoutInflater.from(OtrosDetailFragment.fragment.context);
var view = factory.inflate(R.layout.sample, null)
[...]
vacationDialog.setView(view)
val window = vacationDialog.create()
vacationDialog.setPositiveButton("Cerrar"){dialog, which ->
dialog.dismiss()
}
/**Listener called when the AlertDialog is shown**/
vacationDialog.show()
window.setOnShowListener {
/**Get the positive button from the AlertDialog**/
val positiveButton = window.getButton(DialogInterface.BUTTON_POSITIVE)
/**Set your color to the positive button**/
positiveButton.setBackgroundColor(ContextCompat.getColor(fragment.context!!, R.color.colorPrimary))
positiveButton.setTextColor(ContextCompat.getColor(fragment.context!!, R.color.colorPrimary))
positiveButton.setHintTextColor(ContextCompat.getColor(fragment.context!!, R.color.colorPrimary))
positiveButton.setLinkTextColor(ContextCompat.getColor(fragment.context!!, R.color.colorPrimary))
}
This is the style DialogTheme defined in styles.xml, in which, by the way, I cannot find a way to change the default button color (black), and seems to override any change tried from code.
<style name="DialogTheme" parent="android:Theme.Holo">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<!-- No backgrounds, titles or window float -->
<item name="android:windowBackground">#color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:gravity">center</item>
</style>
Any idea on how to approach this issue?
If you are using an AppCompat theme you can use something like:
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<!-- Used for the buttons -->
<item name="colorAccent">#FFCC00</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">#FFFFFF</item>
<!-- Used for the background -->
<item name="android:background">#5fa3d0</item>
</style>
With the new Material components for android library you can use the new androidx.appcompat.app.AlertDialog.
Just use something like:
new MaterialAlertDialogBuilder(context)
.setTitle("Dialog")
.setMessage("Lorem ipsum dolor ....")
.setPositiveButton("Ok", /* listener = */ null)
.setNegativeButton("Cancel", /* listener = */ null)
.show();
You can customize your theme with something like:
<!-- Alert Dialog -->
<style name="MyThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="#style/ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="buttonBarPositiveButtonStyle">#style/PositiveButtonStyle</item>
<item name="buttonBarNegativeButtonStyle">#style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
</style>
and:
<style name="PositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">#FFFFFF</item>
<item name="backgroundTint">#color/selector_bt</item>
</style>
If you use custom layout then you can change anything easily. Follow the code below:
private fun showAlertDialog(activity: Activity){
val dialog = Dialog(activity)
dialog.setContentView(R.layout.dialog_layout)
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
dialog.show()
}
You can create your custom layout for AlertDialog and inflate it in your custom class extending AlertDialog.
Use androidx.appcompat.app.AlertDialog rather than normal android.app.AlertDialog
How to combine BottomSheetDialogFragment theme with other themes?
My app has skins which are made using themes. BottomSheetDialogFragment should have rounded corners, and I achieve this using:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme) /* hack to make background transparent */
}
Then in styles.xml:
<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">#android:color/transparent</item>
</style>
<style name="CustomBottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="bottomSheetStyle">#style/CustomBottomSheetStyle</item>
</style>
But If I extend from the Theme.MaterialComponents.Light.BottomSheetDialog I do not get the color scheme which I have defined in the skin theme.
So the question is: How to define Dialog theme inside the skin theme?
You can add in your app theme the bottomSheetDialogTheme attribute to set globally in your app the bottomsheetDialog style.
<style name="AppTheme" parent="Theme.MaterialComponents.*">
......
<item name="bottomSheetDialogTheme">#style/BottomSheetDialog_Rounded</item>
</style>
<style name="BottomSheetDialog_Rounded" parent="#style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
<item name="bottomSheetStyle">#style/BottomSheet_Rounded</item>
</style>
Otherwise in your BottomSheetDialogFragment you can override the getTheme() method.
public class RoundedBottomSheetDialog extends BottomSheetDialogFragment {
//....
#Override public int getTheme() {
return R.style.BottomSheetDialog_Rounded;
}
}
Also to get rounded corners you can use something like:
<!-- BottomSheet Dialog-->
<style name="BottomSheetDialog_Rounded" parent="#style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
<item name="bottomSheetStyle">#style/BottomSheet_Rounded</item>
</style>
<style name="BottomSheet_Rounded" parent="Widget.MaterialComponents.BottomSheet">
<item name="shapeAppearanceOverlay">#style/ShapeAppearanceBottomSheetDialog_Rounded</item>
</style>
<style name="ShapeAppearanceBottomSheetDialog_Rounded" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopRight">16dp</item>
<item name="cornerSizeTopLeft">16dp</item>
<item name="cornerSizeBottomRight">0dp</item>
<item name="cornerSizeBottomLeft">0dp</item>
</style>
Try this instead
kotlin
override fun getTheme(): Int = R.style.CustomBottomSheetDialogTheme
java
#Override
public int getTheme() {
return R.style.CustomBottomSheetDialogTheme
}
override fun onCreateDialog(#Nullable savedInstanceState: Bundle?): Dialog
val dialog = BottomSheetDialog(context!!,R.style.FullScreenBottomSheet)
<style name="FullScreenBottomSheet"
parent="Theme.MaterialComponents.Light.BottomSheetDialog">
<item name="android:windowFullscreen">false</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowBackground">#color/transparent</item>
<item name="android:statusBarColor">#color/transparent</item>
</style>
I am having trouble changing the width of the Appcompat PopupMenu because the menu item uses this layout abc_popup_menu_item_layout.xml in MenuPopupHelper.java, which set menu item minWidth to 196dip.
<android.support.v7.internal.view.menu.ListMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?attr/dropdownListPreferredItemHeight"
android:minWidth="196dip"
android:paddingRight="16dip">
I tried to override minWidth as well as dropDownWidth in the following properties in my style.xml. I also tried to override minWidth in android:dropDownItemStyle, but it did not help. I start to wonder if it is possible to override this hard coded attribute of ListMenuItemView. Has anyone succeeded in modifying a PopupMenu width?
<style name="OrderDetailsActivity" parent="AppTheme">
<item name="android:textAppearanceLargePopupMenu">#style/OrderDetailsPopupMenuTextAppearanceLarge</item>
<item name="android:textAppearanceSmallPopupMenu">#style/OrderDetailsPopupMenuTextAppearanceSmall</item>
<item name="android:dropDownListViewStyle">#style/OrderDetailsListDropDownStyle</item>
<item name="dropDownListViewStyle">#style/OrderDetailsListDropDownStyle</item>
</style>
<style name="OrderDetailsPopupMenuTextAppearanceLarge" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Large">
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">#dimen/font_size_medium</item>
</style>
<style name="OrderDetailsPopupMenuTextAppearanceSmall" parent="#android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small">
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textSize">#dimen/font_size_medium</item>
</style>
<style name="OrderDetailsListDropDownStyle" parent="Widget.AppCompat.ListView.DropDown">
<item name="android:divider">#drawable/list_divider</item>
</style>
You can prepare your custom popup menu item layout file and update this static field using reflection in onCreate() method of Your Application class:
private void updatePopUpMenuItemLayout() {
try {
Field field = MenuPopupHelper.class.getDeclaredField("ITEM_LAYOUT");
field.setAccessible(true);
field.set(null, R.layout.custom_popup_menu_item_layout);
} catch (Exception e) {
Log.e("TAG", e.getMessage());
}
}
I'm trying to customize casting controller dialog and I have problems changing dialog's title style. I've implemented it like CCL library does but without success.
This is my relevant code:
VideoMediaRouteControllerDialog.java
public VideoMediaRouteControllerDialog(Context context) {
super(context, xxx.xxx.R.style.TTNCastDialog);
...
}
VideoMediaRouteControllerDialogFragment.java
public class VideoMediaRouteControllerDialogFragment extends MediaRouteControllerDialogFragment {
#Override
public VideoMediaRouteControllerDialog onCreateControllerDialog(Context context, Bundle savedInstanceState) {
VideoMediaRouteControllerDialog customControllerDialog = new VideoMediaRouteControllerDialog(context);
customControllerDialog.setVolumeControlEnabled(false);
return customControllerDialog;
}
}
VideoMediaRouteDialogFactory.java
public class VideoMediaRouteDialogFactory extends MediaRouteDialogFactory {
#Override
public VideoMediaRouteControllerDialogFragment onCreateControllerDialogFragment() {
return new VideoMediaRouteControllerDialogFragment();
}
}
styles.xml
<style name="TTNCastDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowTitleStyle">#style/TTNCastDialogWindowTitle</item>
</style>
<style name="TTNCastDialogWindowTitle">
<item name="android:textSize">22sp</item>
<item name="android:textColor">#color/ccl_mr_custom_title</item>
</style>
styles.xml(v21)
<style name="TTNCastDialog" parent="android:Theme.Material.Dialog">
<item name="android:windowTitleStyle">#style/TTNCastDialogWindowTitle</item>
</style>
I've taken a look at MediaRouteThemeHelper's getButtonTextColor method
and it returns accent color instead of primary color. My application theme extends of Theme.AppCompat.Light.NoActionBar
I've tried this way too
styles.xml
<style name="TTNCastDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowTitleStyle">#style/TTNCastDialogWindowTitle</item>
</style>
<style name="TTNCastDialogWindowTitle">
<item name="android:textSize">22sp</item>
<item name="android:textColor">#color/ccl_mr_custom_title</item>
</style>
But it did not work.
Any suggestions?
Thanks
I have an AppCompatActivity which contains android.app.Fragment. In fragment I have a button on the toolbar which fires the method showDialog():
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_add_ingredient) {
showDialog();
return true;
}
return super.onOptionsItemSelected(item);
}
private void showDialog() {
// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// 2. Chain together various setter methods to set the dialog
// characteristics
builder.setTitle(R.string.dialog_ingredient_add_title);
builder.setView(mActivityMain.getLayoutInflater().inflate(
R.layout.dialog_shopping_ingredient_add, null));
builder.setPositiveButton(R.string.dialog_ingredient_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.dialog_ingredient_cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
// 3. Get the AlertDialog from create()
dialog = builder.create();
dialog.show();
}
As it can be seen from the code, a android.support.v7.app.AlertDialog appears.
Picture 1. AlertDialog shown.
Then I select some text.
Picture 2. Text selected.
And somehow text selection tool shows only half of it and is unclickable.
My styles.xml file is below.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- colorPrimary is used, for instance, for the default ActionBar (but not Toolbar) background. We specify the same color for the toolbar background in toolbar.xml.. -->
<item name="colorPrimary">#color/color_primary</item>
<!-- colorPrimaryDark is used for the status bar (with the battery, clock, etc). -->
<item name="colorPrimaryDark">#color/color_primary_dark</item>
<!-- colorAccent is used as the default value for colorControlActivated which is used to tint widgets. -->
<item name="colorAccent">#color/color_accent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:itemTextAppearance">#style/MenuTextApearance</item>
<item name="colorControlNormal">#000000</item>
<item name="colorControlActivated">#color/color_highlight_text</item>
<item name="colorControlHighlight">#color/color_highlight_text</item>
<item name="actionMenuTextColor">#android:color/white</item>
<item name="android:actionMenuTextColor">#android:color/white</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:textColorHighlight">#color/color_highlight_text</item>
<item name="actionModeBackground">#drawable/myapp_action_mode_background</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<style name="MenuTextApearance" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#000000</item>
</style>
<style name="ActionBarThemeOverlay" parent="">
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="colorControlNormal">#FFFFFF</item>
<item name="colorControlHighlight">#00000000</item>
</style>
<style name="HeaderBar">
<item name="android:background">?colorPrimary</item>
</style>
<style name="HeaderBarTransparent">
<item name="android:background">#color/color_primary_transparent</item>
</style>
<style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Light">
<item name="android:background">#00000000</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Question:
How can I make the text selection tool fully visible and clickable?