我正在使用 datePicker 输入日期。
<style name="DatePickerTheme" parent="@android:style/Theme.Holo.Light.Dialog.MinWidth">
<item name="android:windowMinWidthMajor">@android:dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@android:dimen/dialog_min_width_minor</item>
</style>
Run Code Online (Sandbox Code Playgroud)
并在 Activity.java 中
public void showDatePickerDialog(View v) {
DialogFragment newFragment = new Login.DatePickerFragment();
newFragment.show(getSupportFragmentManager(), "datePicker");
}
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new DatePickerDialog(getActivity(), R.style.DatePickerTheme, this, 1995, 0, 1);
}
public void onDateSet(DatePicker view, int year, int month, int day){
dateSelected = year+"-"+month+"-"+day;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我得到了一个我不想要的背景图块。
但我想要
我想为我的应用程序创建一个样式Seekbar。我只想改变拇指和酒吧本身的颜色。
我设法像这样更改拇指名称:
<style name="MySeekBar" parent="@style/Widget.AppCompat.SeekBar">
<item name="android:thumbTint"> @color/turquoise </item>
</style>
Run Code Online (Sandbox Code Playgroud)
但我不确定如何更改栏的颜色。我知道如何用代码来做,但不在 xml 中:
seekBar.getProgressDrawable().setColorFilter(getContext().getResources().getColor(R.color.turquoise), Mode.SRC_ATOP);
Run Code Online (Sandbox Code Playgroud)
如何使用 xml 中定义的样式设置颜色过滤器的样式?
我有一个简单的警报对话框,其中包含单选项目
val alertDialog = AlertDialog.Builder(this)
alertDialog.setTitle("My Title")
val array = arrayOf("aa", "bb", "cc")
alertDialog.setSingleChoiceItems(array, 0) { _, selectedItem ->
}
alertDialog.setNegativeButton("Cancel") { _, _ ->
}
alertDialog.create()
alertDialog.show()
Run Code Online (Sandbox Code Playgroud)
我已将警报对话框的自定义样式添加到我的主题中
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
.........
<item name="android:timePickerDialogTheme">@style/DefaultAlertDialogTheme</item>
<item name="android:datePickerDialogTheme">@style/DefaultAlertDialogTheme</item>
<item name="android:alertDialogTheme">@style/DefaultAlertDialogTheme</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这是我的风格
<style name="DefaultAlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:colorAccent">@color/greenButtonBackgroundColor</item>
<item name="android:textColorSecondary">@color/greenButtonBackgroundColor</item>
<!--title-->
<item name="android:textColor">@color/toolbarTitleTextColor</item>
</style>
Run Code Online (Sandbox Code Playgroud)
当我运行该应用程序时,我看到此警报
有没有办法在不创建自定义布局的情况下更改单选按钮附近文本的颜色?
最近我切换到使用com.google.android.material:material:1.0.0应用程序主题。
除了 set colorPrimary, colorPrimaryDarkand colorAccentusing MaterialButtonwith Widget.MaterialComponents.Buttonstyle 之外,activity/fragment和bottomSheetFragment中的按钮颜色不同!
在活动/片段中是可以的。但在BottomSheet中有不同的颜色(绿色)。
android android-styles material-design bottom-sheet material-components-android
我正在使用 AndroidX 支持库。在我的清单中,我声明:
<application
...
android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)
在values.styles.xml我声明:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:imageButtonStyle">@style/MyImageButton</item>
</style>
<style name="MyImageButton" parent="Widget.AppCompat.ImageButton">
<item name="android:background">@android:color/transparent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后我通过以下方式使用 ImageButton:
<ImageButton
android:id="@+id/image"
android:layout_width="40dp"
android:layout_height="40dp" />
Run Code Online (Sandbox Code Playgroud)
不幸的是,我ImageButton显示的是灰色背景而不是透明背景。我该怎么做才能修复它?
我有一个TextInputLayout需要大量重用的自定义样式,因此我尝试将其转换为自定义视图。
这是要重用的 xml:
<com.google.android.material.textfield.TextInputLayout
style="@style/TextInputLayoutAppearance"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
TextInputLayoutAppearance是我在中创建的自定义样式styles.xml
这是我的自定义视图的类:
class OutlinedTextInput @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : TextInputLayout(context, attrs, defStyleAttr) {
init {
LayoutInflater.from(context).inflate(R.layout.view_outlined_textinput, this, true)
}
}
Run Code Online (Sandbox Code Playgroud)
这是view_outlined_textinput我根据上面的原始 xml 改编的,用于自定义视图:
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:parentTag="com.google.android.material.textfield.TextInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</merge>
Run Code Online (Sandbox Code Playgroud)
这里有两件事需要注意:
布局使用合并标签来避免视图层次结构中的冗余视图。
应用自定义样式至关重要。使用 style= 语法在原始 xml 中应用样式。但是,由于合并标签用于自定义视图,因此无法以这种方式完成。
我尝试按如下方式设置样式,但没有成功:
class OutlinedTextInput @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = …Run Code Online (Sandbox Code Playgroud) android-custom-view android-layout android-styles android-textinputlayout android-textinputedittext
我有带有黑色导航栏的夜间主题,在应用程序主题参数中设计
<item name="android:navigationBarColor">@color/color_navbar</item>
<item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">false</item>
Run Code Online (Sandbox Code Playgroud)
但是当我显示 DialogFragment 时,导航栏颜色变为白色。晚上对眼睛伤害很大。
我尝试设置dialogfragment样式但它对我没有帮助:
public void onCreate(Bundle savedInstanceState) {
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Theme_AppCompat_DayNight_Dialog);
super.onCreate(savedInstanceState);
}
Run Code Online (Sandbox Code Playgroud)
我的基本应用程序风格是Theme.MaterialComponents.DayNight.NoActionBar
我在 android Q 上测试它。
那么在对话框片段上自定义导航栏颜色的方法是什么?或者,如果有一种方法可以在显示对话框片段时不更改导航栏颜色,并使用显示此对话框的活动中的颜色,那就更好了。
android android-dialogfragment android-styles android-night-mode
我想设计一个圆角的TextView和。EditText
对于这个问题有一个直接的解决方案。使用自定义形状背景。但由于 Material Design 1.1.0 引入了shapeAppearance主题属性,可以将不同的形状应用于角,这对于所有 Material 组件(如MaterialButton、BottomSheet、MaterialCardView等)都适用。但它不适用于EditText和TextView。我MaterialTextView也尝试使用,但没有成功。这也是我设置风格的方式也EditText类似TextView。
<style name="ThemeOverlay.Chat" parent="AppTheme">
<item name="editTextStyle">@style/Overlay.Chat.EditText</item>
</style>
<style name="Overlay.Chat.EditText" parent="Widget.AppCompat.EditText">
<item name="shapeAppearanceOverlay">@style/ShapeAppearance.Overlay.FullRound</item>
</style>
<style name="ShapeAppearance.Overlay.FullRound" parent="ShapeAppearance.MaterialComponents.LargeComponent">
<item name="cornerSize">50dp</item>
</style>
Run Code Online (Sandbox Code Playgroud) android android-theme android-edittext android-styles material-components-android
我有一个具有锐利矩形背景的菜单。我已经尝试了很多,但无法将其更改为圆形背景。 弹出菜单.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1F2026"
android:orientation="horizontal"
>
<TextView
android:id="@+id/details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:fontFamily="@font/quicksand_regular"
android:text="@string/add_to_favourite"
android:textColor="@color/icon_color_dark" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
上面给出的是我的弹出菜单 xml。
public static void showAlbumPopupOptions(final Activity activity, ImageView listMore,
final Song song, String songId, int playingState) {
final boolean isLogged = AppController.getBooleanPreference(Constants.LOGGED_IN, false);
String[] listItems;
listItems = activity.getResources().getStringArray(R.array.popup_menu_add_album);
ArrayAdapter<String> mPopupAdapter = new ArrayAdapter<>(activity, R.layout.popup_menu, R
.id.details, listItems);
final ListPopupWindow albumPopup = new ListPopupWindow(activity);
albumPopup.setContentWidth(Utils.measureContentWidth(mPopupAdapter, activity));
albumPopup.setAdapter(mPopupAdapter);
albumPopup.setHeight(ListPopupWindow.WRAP_CONTENT);
albumPopup.setAnchorView(listMore);
albumPopup.setModal(true);
albumPopup.setDropDownGravity(Gravity.END);
final LoadingProgressDialog loadingProgressDialog = new LoadingProgressDialog(activity, R
.style
.DialogThemeProgress, false); …Run Code Online (Sandbox Code Playgroud) android popupmenu android-styles android-popupwindow material-components-android
android-styles ×10
android ×9
material-components-android ×3
alert ×1
androidx ×1
bottom-sheet ×1
dialog ×1
popupmenu ×1