我目前正在挖掘 Google IO 2019 android 应用程序的代码。在styles.xml第 77 行中,它说:
<style name="TextAppearance.IOSched.Body2" parent="TextAppearance.MaterialComponents.Body2" />
Run Code Online (Sandbox Code Playgroud)
但是我在哪里可以找到父级的定义TextAppearance.MaterialComponents.Body2?我的 Android Studio 中已经有本地 IO 项目,以防有助于解决该定义背后的内容。
谢谢!
android android-appcompat material-design material-components material-components-android
如何在未TextInputLayout聚焦时更改边框和颜色?
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_height="wrap_content"
app:boxStrokeWidth="4dp"
app:boxStrokeColor="@color/colorPrimary"
app:layout_constraintTop_toBottomOf="@id/a">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:hint="@string/app_name"
android:textColorHint="@color/colorPrimary"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我尝试:
app:boxStrokeWidth="4dp"
app:boxStrokeColor="@color/colorPrimary"
Run Code Online (Sandbox Code Playgroud)
但是,不能在不聚焦的情况下工作
android android-xml android-textinputlayout material-components material-components-android
我正在研究当前 Android 应用程序中的 CardView 和深色主题
当启用暗模式时,除了 CardViews 之外,我的大部分应用程序都按预期工作。
我的 Gradle 和这个很像
android {
compileSdkVersion 29
defaultConfig {
applicationId "org.application.investigation"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
implementation 'androidx.cardview:cardview:1.0.0'
Run Code Online (Sandbox Code Playgroud)
我的主题如下:-
<resources>
<style name="AppTheme" parent="@style/Theme.MaterialComponents.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorError">@color/design_default_color_error</item>
<item name="android:textColor">?attr/colorOnBackground</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>
Run Code Online (Sandbox Code Playgroud)
我的 CardView 布局类似于:-
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_films_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="?android:attr/colorBackground"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true"
tools:context=".films.Films">
<LinearLayout
android:id="@+id/item_films_film" …Run Code Online (Sandbox Code Playgroud) android android-cardview material-components-android android-dark-theme
我正在尝试以编程方式将带有 EditText 的 TextInputLayout 添加到 LinearLayout。我的做法:
TextInputLayout textInputLayout = new TextInputLayout(new ContextThemeWrapper(getContext(), R.style.Widget_MaterialComponents_TextInputLayout_OutlinedBox));
textInputLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
textInputLayout.setHintTextAppearance(R.style.Base_Widget_MaterialComponents_TextInputLayout_TextInputLayout);
TextInputEditText editText = new TextInputEditText(getContext());
editText.setHint("test");
textInputLayout.addView(editText, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
linearLayout.addView(textInputLayout);
Run Code Online (Sandbox Code Playgroud)
然而,结果看起来非常错误:
奇怪的是,通过 XML 添加相同的 TextInputLayout 有效:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="kommentar"
app:hintTextAppearance="@style/Base.Widget.MaterialComponents.TextInputLayout.TextInputLayout">
<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)
现在,我需要补充一点,在升级到Material 1.1之前,编程方法是有效的。我只使用材料组件。我怎样才能解决这个问题?
java android material-design android-textinputlayout material-components-android
//Material Date Picker
private val calendar = Calendar.getInstance()
private val constraintsBuilder = CalendarConstraints.Builder().setStart(calendar.timeInMillis)
private val builder = MaterialDatePicker.Builder.datePicker()
private val picker = builder
.setSelection(calendar.timeInMillis)
.setInputMode(MaterialDatePicker.INPUT_MODE_CALENDAR)
.setCalendarConstraints(constraintsBuilder.build())
.build()
Run Code Online (Sandbox Code Playgroud)
我正在使用上面的代码打开日历 setSelection 方法选择当前日期和 setStart 只适用于当月所以我无法选择上个月的日期但我仍然可以选择当月的过去日期。
如果有人可以帮助我。请告诉我。谢谢。
android datepicker android-datepicker material-components material-components-android
当我想在 EditText 中写我的提示与 OutlinedBox 重叠时,我的提示有问题,所以我不明白是什么问题。所以这是我的代码
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/text_input_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:drawableStart="@drawable/ic_action_name"
android:hint="@string/Enter_Username"
android:inputType="textPersonName"/>
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我的问题:
xml android android-textinputlayout textinputlayout material-components-android
我正在尝试制作类似以下示例的内容:
我希望在我从服务器验证用户名时显示可绘制对象。
我正在使用 Material Design 文本输入字段和 EditText。是的,我可以使用 simpleEditText和 an 来完成ImageView,但我想使用标准元素。
我查看了官方文档,有一种方法可以使用XML在右上角添加图像,但我想以编程方式添加它。
android android-edittext android-textinputlayout material-components-android
我正在使用 Material 在 android studio 中使用 Java 设计一个带有下拉列表的表单。
我想将用户从下拉列表中所做的选择保存到一个字符串中,这样我就可以将其保存到 Firebase,但是当我尝试记录结果时,它说选择为空。
有谁知道我如何捕获用户从这种类型的下拉菜单中选择的内容?我以前确实有一个可以工作的 Spinner,但这似乎并没有以相同的方式工作。
我的XML代码如下
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/cpdTypeLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:hint="Activity Type">
<AutoCompleteTextView
android:id="@+id/cpdType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我的 AddAdactivity.java 代码是
//CPD TYPE DROPDOWN MENU
cpdTypeLayout = findViewById(R.id.cpdTypeLayout);
cpdType = findViewById(R.id.cpdType);
String[] type = new String[]{
"Formal Education Completed", "Other Completed", "Professional Activities", "Self-Directed Learning", "Work-Based Learning"
};
ArrayAdapter<String> adapterType = new ArrayAdapter<>(
AddActivity.this,
R.layout.dropdown_item,
type
);
cpdType.setAdapter(adapterType);
cpdType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int …Run Code Online (Sandbox Code Playgroud) java android android-spinner android-textinputlayout material-components-android
我已按如下方式设置我的应用程序:
构建.gradle
implementation 'com.google.android.material:material:1.1.0'
样式文件
<style name="AlertDialogTheme" parent="ThemeOverlay.MaterialComponents.Dialog.Alert">
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
</style>
<style name="NegativeButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:color">@color/colorPrimary</item>
</style>
<style name="PositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:color">@color/colorPrimary</item>
</style>
Run Code Online (Sandbox Code Playgroud)
CheckoutFragment.kt
private fun createConfirmOrderDialog() {
val builder = AlertDialog.Builder(requireContext(), R.style.AlertDialogTheme)
builder.setTitle(getString(R.string.confirm_order))
.setMessage(dialogPrompt)
.setPositiveButton(R.string.confirm) { dialog, _ ->
viewModel.placeOrder()
dialog.dismiss()
}
.setNegativeButton(R.string.cancel) { dialog, _ ->
dialog.dismiss()
}
builder.show()
}
Run Code Online (Sandbox Code Playgroud)
颜色文件
<color name="colorAccent">#F1CB1A</color> // I have this added to the base theme
但是,此设置显示了一个对话框,其中按钮文本不可见,因为文本和背景都是白色的。
我怎样才能解决这个问题?
android android-theme android-alertdialog android-ktx material-components-android
我想实现一个类似于这样的进度条:
在材料的设计文档,它说我需要设置indeterminateAnimationType来contiguous实现这一目标,并提供三种颜色。但是当indicatorColor属性只接受一种颜色时如何提供三种颜色?
当我运行这段代码时,它抛出一个异常说Contiguous indeterminate animation must be used with 3 or more indicator colors:
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
app:indeterminateAnimationType="contiguous"
app:hideAnimationBehavior="outward"
app:showAnimationBehavior="inward"
app:trackThickness="5dp" />
Run Code Online (Sandbox Code Playgroud) xml android android-progressbar material-design material-components-android
android ×10
material-components-android ×10
java ×2
xml ×2
android-ktx ×1
android-xml ×1
datepicker ×1