我正在使用 Material 组件创建 DatePicker。据我了解,colorPrimary用于确定对话框顶部部分的颜色,以及按钮上文本的颜色,特别是CANCEL和OK。
浏览文档,我似乎找不到一种方法来更改底部按钮的颜色?可以这样做吗?
当前代码:
<style name="ThemeOverlay.App.DatePicker" parent="@style/ThemeOverlay.MaterialComponents.MaterialCalendar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorOnPrimary">@android:color/white</item>
<item name="shapeAppearanceSmallComponent">@style/ShapeAppearance.App.SmallComponent</item>
<item name="shapeAppearanceMediumComponent">@style/ShapeAppearance.App.MediumComponent
</item>
<item name="materialCalendarHeaderTitle">@style/MyHeaderTitle</item>
<item name="colorOnPrimarySurface">@android:color/white</item>
</style>
<style name="MyHeaderTitle" parent="Widget.MaterialComponents.MaterialCalendar.HeaderTitle">
<item name="android:textColor">@android:color/white</item>
</style>
<style name="ThemeMaterialCalendarTextButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog.Flush">
<item name="android:textColor">@android:color/white</item>
<item name="iconTint">@android:color/white</item>
</style>
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="android:textSize">24sp</item>
<item name="cornerSize">16dp</item>
</style>
<style name="ShapeAppearance.App.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">
<item name="android:textSize">30sp</item>
<item name="cornerSize">16dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用日期选择器和扩展对话框片段的时间选择器.我在运行应用程序时能够获取日期选择器,但是当我添加时间选择器时,我收到错误无法解析方法DateFormat.is24HourFormat.
我使用的是import android.support.v4.app.DialogFragment; 按照帖子
TimepickerFragment show()方法无法解析
但问题仍然存在
主要活动
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class MainActivity extends AppCompatActivity implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void datePicker(View view) {
DatePickerFragment fragment = new DatePickerFragment();
fragment.show(getSupportFragmentManager(), "date");
}
public void TimePicker(View view) {
TimePickerFragment fragment = new TimePickerFragment();
fragment.show(getSupportFragmentManager(), "time");
}
private void …Run Code Online (Sandbox Code Playgroud) 我正在使用日期选择器,我需要用不同的颜色设置样式。除了选定的日期颜色,所有其他东西都工作正常。选择的日期颜色默认为“ android:textColorPrimaryInverse”,在我的情况下为红色,对话框背景为白色,“ android:colorControlHighlight”和“ android:colorControlActivated”也为红色。
这意味着所选的文本颜色不会显示。我需要将其显示为白色,但是问题是如果我将“ android:textColorPrimaryInverse”更改为白色,则背景为白色时我的标题将不会显示。
这是我的样式文件:
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/color_white</item>
<item name="android:textColorPrimaryInverse">@color/red</item>
<item name="android:textColorSecondaryInverse">@color/red</item>
<item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
<item name="buttonBarButtonStyle">@style/DialogButtonStyle</item>
<item name="android:colorControlHighlight">@color/red</item>
<item name="android:colorControlActivated">@color/red</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这就是我显示对话框的方式
new DatePickerDialog(mActivity, R.style.DialogTheme, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
//DO SOMETHING
}
}, 2015, 02, 26).show();
Run Code Online (Sandbox Code Playgroud) 嗨,我正在制作一个约会应用程序,我使用firebase 数据库作为我的后端。
我想限制用户选择以前的日期。我从这里得到了解决方案
但我不知道把代码放在哪里才能让它工作。我把我的代码放在下面,请指导我做同样的事情......
另一个问题是,如果用户改变系统日期和时间将在日期选择日期也改变了,有什么办法,我可以限制用户选择当前日期或明天的日期只,但不是昨天的日期。
例如。取 ServerValue.TIMESTAMP 并将其转换为日期,然后比较所选日期和从 TIMESTAMP 获得的日期。
约会.java
/**
* A simple {@link Fragment} subclass.
*/
public class Appointment extends Fragment {
@BindView(R.id.apointFirstName)
EditText apointFirstName;
@BindView(R.id.apointLastName)
EditText apointLastName;
@BindView(R.id.apointPhoneNumber)
EditText apointPhoneNumber;
@BindView(R.id.apointEmail)
EditText apointEmail;
@BindView(R.id.apointDate)
EditText apointDate;
@BindView(R.id.availTimeSpinner)
Spinner availTimeSpinner;
@BindView(R.id.bookAppointmentButton)
Button book_btn;
@BindView(R.id.cancelAppointmentButton)
Button cancel_btn;
Calendar mCal;
int day, month, year;
String mCurrentDate;
String fname,lname,email;
int phone;
String timestamp = String.valueOf(ServerValue.TIMESTAMP);
public Appointment() {
// Required …Run Code Online (Sandbox Code Playgroud) 我尝试了下面的代码,但它给了我两天前星期几的名称。
DatePicker picker;
int date = picker.DayOfMonth;
int month = (picker.Month + 1);//month is 0 based
int year = picker.Year;
SimpleDateFormat simpledateformat = new SimpleDateFormat("EEE");
Date dt = new Date(year, month, date);
Run Code Online (Sandbox Code Playgroud)