android-layout 相关问题

布局定义用户界面的可视结构,例如活动,片段或应用程序窗口小部件的UI。

如何在Android中使用日期选择器

我想在Android中使用日期选择器。这是我的 XML 代码。出发日期应从当前日期开始,返回日期应大于我的出发日期 我想在 Android 中使用日期选择器。这是我的 XML 代码。出发日期应从当前日期开始,返回日期应大于我的出发日期 <LinearLayout android:id="@+id/dateLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/fromToLayout" android:baselineAligned="false" android:orientation="horizontal" > <LinearLayout android:id="@+id/departdateLayout" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:orientation="vertical" > <TextView android:id="@+id/deparDateTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="7dp" android:gravity="center_horizontal" android:text="@string/departdate" /> <TextView android:id="@+id/departDate" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="dd/mm/yyyy" /> </LinearLayout> <LinearLayout android:id="@+id/returndateLayout" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:orientation="vertical" > <TextView android:id="@+id/returndata" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="7dp" android:gravity="center_horizontal" android:text="@string/returndate" /> <TextView android:id="@+id/returnDate" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="dd/mm/yyyy"/> </LinearLayout> </LinearLayout> 我想使用日期选择器来代替其 id returnDate 和出发日期的 TextView,以便用户单击日历从那里打开,他可以选择日期并将该日期填充到此 Texview 中 尝试以下方法。 TextView departDate = (Button) findViewById(R.id.departDate); departDate.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { Calendar calender = Calendar.getInstance(); Dialog mDialog = new DatePickerDialog(IncomeActivity.this, mDatesetListener, calender.get(Calendar.YEAR), calender.get(Calendar.MONTH), calender .get(Calendar.DAY_OF_MONTH)); mDialog.show(); } }); 然后将以下代码编写为单独的方法。 private DatePickerDialog.OnDateSetListener mDatesetListener = new OnDateSetListener() { public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) { arg2 = arg2 + 1; String my_date = arg1 + "-" + arg2 + "-" + arg3; departDate.setText(my_date); } }; 希望这对您有帮助。 你可以做这样的事情:- public class mExample extends Activity { private TextView returnDate; private int year; private int month; private int day; static final int DATE_PICKER_ID = 1111; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); returnDate= (TextView) findViewById(R.id.returnDate); // Get current date by calender final Calendar c = Calendar.getInstance(); year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH); day = c.get(Calendar.DAY_OF_MONTH); // Show current date returnDate.setText(new StringBuilder() // Month is 0 based, just add 1 .append(month + 1).append("-").append(day).append("-") .append(year).append(" ")); returnDate.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // On click show datepicker dialog showDialog(DATE_PICKER_ID); } }); } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_PICKER_ID: // open datepicker dialog. // set date picker for current date // add pickerListener listner to date picker return new DatePickerDialog(this, pickerListener, year, month,day); } return null; } private DatePickerDialog.OnDateSetListener pickerListener = new DatePickerDialog.OnDateSetListener() { // when dialog box is closed, below method will be called. @Override public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) { year = selectedYear; month = selectedMonth; day = selectedDay; // Show selected date returnDate.setText(new StringBuilder().append(month + 1) .append("-").append(day).append("-").append(year) .append(" ")); } }; } 我制作了这个非常简单的存储库来说明日期时间选择器遵循材料组件指南 https://github.com/mbbiosio/MaterialDatePicker-Google 希望它能帮助你理解这一点 尝试使用此代码解决您的所有问题 public class SearchFlight extends Activity { EditText depart,returnDate; Calendar myCalendar; int val; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_flight); depart=(EditText)findViewById(R.id.departDate); returnDate=(EditText)findViewById(R.id.returnDate); myCalendar = Calendar.getInstance(); final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // TODO Auto-generated method stub myCalendar.set(Calendar.YEAR, year); myCalendar.set(Calendar.MONTH, monthOfYear); myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); updateLabel(val); } }; depart.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub new DatePickerDialog(SearchFlight.this, date, myCalendar .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); val=1; } }); returnDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub new DatePickerDialog(SearchFlight.this, date, myCalendar .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show(); val=2; } }); } private void updateLabel(int val) { String myFormat = "dd/MM/yy"; //In which you need put here SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US); if(val==1) depart.setText(sdf.format(myCalendar.getTime())); else returnDate.setText(sdf.format(myCalendar.getTime())); } }

回答 4 投票 0

无法在WebView中打开PDF文档

我正在使用WebView打开一个url,它实际上是一个pdf文档。这是代码片段。 WebView webView = (WebView) context.findViewById(R.id.webView1); webView.getSettings().setJavaScriptEnab...

回答 3 投票 0

编辑文本底部没有线条

我想让我的编辑文本字段没有底部的线条,就像这张图片一样 现在我的编辑文本看起来像这样 我该怎么办?

回答 4 投票 0

Android Studio 说“androidx.drawerlayout.widget.DrawerLayout”在项目或库中找不到,即使我已经将其添加到 gradle 中

在此输入图像描述 下面还显示了所附同一代码片段中的代码文本。 下面还有来自已附加的同一片段的代码文本。 <androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:openDrawer="start"> 尝试执行以下任一方法: 通过转到“文件”->“关闭项目”来关闭您的 Android 项目。然后再次导入 如果上述选项不适合您,则转到文件 -> 使缓存无效/重新启动 如果它们都不起作用,请删除依赖项并再次添加它,并在 gradle 同步完成时告诉我构建输出 您的工作室缓存可能已损坏; 所以 先关闭你的所有项目;然后 在C:\驱动器中打开工作室路径;例如。它应该像 C:\Users\hp(Your_User_Name)\.AndroidStudio4.0\system\caches...删除这个 caches 文件夹。 现在再次启动您的项目,问题现在就消失了。 希望这对某人有帮助。 我不知道它是否适合你,但它对我有用: 我刚刚启动了该应用程序(该应用程序应该在模拟器中启动)。一旦成功执行,IDE 就不再显示此问题。 不要注释掉 DrawerLayout。如果需要,请将其主体保持为空,然后启动应用程序。

回答 3 投票 0

Kotlin 自定义视图引用 textview 返回 null

我有一个自定义视图: 类 CustomerView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) { private var txtName: TextView 私有变量 txtAge: TextView 在里面 { ...

回答 1 投票 0

在android中实现自定义多个复选框

我想实现这个目标,有人可以帮助我吗?

回答 1 投票 0

如何为轮播项添加点击监听器

我按照本指南使用 MotionLayout 创建了一个轮播:https://developer.android.com/training/constraint-layout/motionlayout/carousel 我已经从本指南中获得了所有内容 - 我...

回答 1 投票 0

在android xml中将两个元素放置在父相对布局的左侧和右侧

我想要在android xml中相对布局左侧的两个元素和同一相对布局右侧的两个元素。我尝试如下。它不起作用。 我的 XML 我想要在 android xml 中相对布局左侧的两个元素和同一相对布局右侧的两个元素。我尝试如下。这不起作用。 我的 XML <androidx.constraintlayout.widget.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" android:background="@color/primary_color" android:id="@+id/linear_parentPl" tools:context=".PlayList"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" android:orientation="vertical" android:background="@drawable/top_bar"> <ImageView android:id="@+id/back_iconPl" android:layout_width="44dp" android:layout_height="44dp" android:src="@drawable/baseline_arrow_back_ios_24" android:layout_marginLeft="16dp" android:layout_marginTop="5dp" android:layout_marginBottom="5dp"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/play_list" android:layout_toRightOf="@+id/back_iconPl" android:textColor="@color/light_orange" android:textStyle="bold" android:textSize="24sp" android:layout_marginTop="10dp"/> <TextView android:id="@+id/logout_text" android:layout_toLeftOf="@+id/logout_iconPl" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/logout_text" android:textColor="@color/white" android:textStyle="bold" android:textSize="14sp" android:layout_marginTop="10dp"/> <ImageView android:id="@+id/logout_iconPl" android:layout_alignParentRight="true" android:layout_width="26dp" android:layout_height="26dp" android:src="@drawable/logoutrounded"/> </RelativeLayout> 任何机构可以帮助我实现这一目标吗? 我的输出是 我建议你放弃相对布局并直接使用约束布局。 给出一些约束应该可以将对象放置在右端。 app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@id/xxx" app:layout_constraintTop_toBottomOf="parent" 其中“@id/xxx”是左侧对象的id。 如果您有多个左侧对象,请将它们包装到另一个约束布局中,并为该约束布局提供一个 id 来引用它。 此外,还可能需要 0dp 的宽度或高度,例如: android:layout_width="0dp" android:layout_height="match_parent" 这将填充宽度或高度的空白空间(两者均不可用)。 详细信息请参见 layout_height="0dp" 是什么意思?

回答 1 投票 0

状态栏与应用程序的工具栏重叠,并且工具栏在 Android API 30+ 上消失了

我在 Android API 30+ 上遇到应用程序工具栏问题。设备的状态栏与我的应用程序的工具栏重叠,并且工具栏消失了。 API 低于 30(29、28、27、...)的设备上不会出现此问题。我

回答 1 投票 0

从服务访问视图

所以基本上,我得到了一个显示乐队列表的列表视图。 当我按下列表中的一个频段时,它会通过适配器创建一个频段配置文件页面。 在这个布局中,我有一个播放按钮,它...

回答 1 投票 0

如何显示大小相等的卡片视图?

我试图显示两张大小相同的卡片,其中一个卡片视图将显示图像,另一个将显示Texview。目前,两个卡片视图的大小不同,如图所示 哈...

回答 1 投票 0

Android Spinner 自定义布局

我正在尝试使用自定义样式自定义我的微调器。 旋转器 我正在尝试使用自定义样式自定义我的微调器。 旋转器 <Spinner android:id="@+id/my_spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/activity_vertical_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_vertical_margin" app:layout_constraintTop_toBottomOf="@id/expense_amount" app:layout_constraintLeft_toRightOf="parent" app:layout_constraintRight_toLeftOf="parent" android:elevation="3dp" /> 这是我的 styles.xml 文件。 styles.xml <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="android:spinnerStyle">@style/AppTheme.spinnerStyle</item> <item name="android:spinnerDropDownItemStyle">@style/AppTheme.spinnerDropDownItemStyle</item> </style> <style name="AppTheme.spinnerStyle" parent="@android:style/Widget.Material.Light.Spinner"> <item name="android:textColor">@android:color/white</item> <item name="android:background">@color/colorPrimary</item> </style> <style name="AppTheme.spinnerDropDownItemStyle" parent="@android:style/Widget.Material.DropDownItem.Spinner"> <item name="android:textColor">@android:color/white</item> <item name="android:background">@color/colorPrimary</item> </style> 这给了我这样的旋转器: 我想添加一个下拉箭头。 当我将微调器更改为下拉箭头代码时,所有文本颜色和背景颜色都会丢失。 显示下拉箭头的微调器代码 <Spinner android:id="@+id/my_spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/activity_vertical_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginTop="@dimen/activity_vertical_margin" app:layout_constraintTop_toBottomOf="@id/expense_amount" app:layout_constraintLeft_toRightOf="parent" app:layout_constraintRight_toLeftOf="parent" android:background="@android:drawable/btn_dropdown" /> 如何保留我的主题以及下拉箭头?? P.S. 我不太擅长在 Linux 机器上捕获屏幕截图。 这是 Android 的正常行为: Spinner 有自己的默认背景,当您使用 styles.xml 自定义它时,它会跟随并变成蓝色。然后在代码中再次将 Spinner 的 android:background 设置为 @android:drawable/btn_dropdown,因此它会覆盖您的样式,因为布局 xml 中的属性比样式中的属性具有更高的优先级。 您没有背景来显示下拉箭头,请使用这个: 第一个解决方案: <Spinner android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Light" android:spinnerMode="dropdown" /> 在你的java文件中 spinner = (Spinner) view.findViewById(R.id.spinner); ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.spinner_data, android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); 第二种解决方案 您将需要在 Spinner 外部使用relativelayout。将您的 <Spinner> 替换为: <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/spinner_bg"> <Spinner android:id="@+id/spinner" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Light" android:spinnerMode="dropdown" /> </RelativeLayout> 然后创建自定义背景并为微调器选择背景颜色: spinner_bg.xml <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:top="8dp" android:bottom="8dp"> <shape> <solid android:color="@color/colorPrimary" /> <corners android:radius="2dp"/> <stroke android:width="1dp" android:color="@color/colorPrimary" /> <padding android:top="16dp" android:bottom="16dp" android:left="8dp" android:right="16dp"/> </shape> </item> </layer-list>

回答 1 投票 0

Jetpack Compose Lazy Table

我当前的目标是实现一个可以表示表格的视图,但是这个表格的列和行中可以包含相当多的元素。我当前的想法是用 LazyRows 填充 LazyColumn。 @

回答 2 投票 0

包裹在 CoordinatorLayout 内的 RecyclerView 在键盘打开时未调整大小

活动布局xml: 活动布局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" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginEnd="64dp" app:expandedTitleMarginStart="48dp" app:layout_scrollFlags="scroll"> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:fitsSystemWindows="true" app:layout_collapseMode="parallax"> <ImageView android:layout_width="match_parent" android:layout_height="250dp" android:scaleType="centerCrop" android:src="@drawable/hospital_logo" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:orientation="vertical" android:padding="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="******* ************* ********** ************" android:textSize="18sp" android:textColor="@android:color/black" android:textStyle="bold"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="***************************" android:textSize="18sp" android:textColor="@android:color/black" android:textStyle="bold"/> </LinearLayout> </FrameLayout> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> </android.support.design.widget.CollapsingToolbarLayout> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabMode="fixed" /> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.CoordinatorLayout> 这里我将 CoordinatorLayout 与 CollapsingToolbarBar 和 ViewPager 一起使用。 我在 ViewPager 中添加了两个带有布局 xml 的片段: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" /> </LinearLayout> recycler_view 的单元格包含 EditText。当我选择 EditText 时,软键盘打开,但 EditText 隐藏在键盘后面。 我已在活动中添加了以下标志: android:windowSoftInputMode="adjustResize" 我正在使用 23.1.1 appcompat 版本的 RecyclerView。 当我用 CoordinatorLayout 替换 LinearLayout 时,RecyclerView 正在调整大小以正确显示最后一个元素。所以我认为这是协调器布局的问题。 我遇到了以下问题https://code.google.com/p/android/issues/detail?id=176406和https://code.google.com/p/android/issues/detail?id =176187 但这与这个错误无关。让我知道我是否可以应用某种路径来解决这个问题。 等待回复。谢谢。 如果需要更多详细信息,请告诉我。 有一个非常相似的问题,并且能够通过使用 android:windowSoftInputMode="adjustPan" 来修复它 我遇到了类似的问题coordinatorLayout。但是,将 fitsSystemWindows 设置为 false 解决了问题。看来罪魁祸首是coordinatorLayout。我通过将整个布局(包括 AppBarLayout)封装在 constraintLayout 中解决了这个问题。 <androidx.coordinatorlayout.widget.CoordinatorLayout> <androidx.constraintlayout.widget.ConstraintLayout <com.google.android.material.appbar.AppBarLayout </com.google.android.material.appbar.AppBarLayout //content here </androidx.constraintlayout.widget.ConstraintLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout> 我知道回复这个帖子来得很晚,但也许对其他人有帮助。 :)

回答 2 投票 0

如何制作全屏 Activity,状态栏位于其顶部,而当 Activity 聚焦于 editText 时,滚动条未完全滚动?

问题是,当我在 EditText 中输入文本时,ScrollView 不起作用并且不会在我的活动中滚动 有趣的状态栏颜色(活动:活动){ val 窗口 = Activity.window //...

回答 4 投票 0

如何在 android kotlin 上关闭 include 标签中的 xml 文件

我想在点击kotlin中包含的xml文件的关闭按钮时关闭在include标签中打开的xml文件。我尝试如下。我无法关闭。有人可以帮我做这件事吗...

回答 1 投票 0

通过键盘的自动更正部分获取软键盘高度

我有一个使用“adjustPan”作为其调整大小配置的活动,并且我需要在不使用“adjustResize”的情况下计算键盘高度,因为我需要将一些视图保留为全屏(这意味着......

回答 2 投票 0

更改EditTextPreference的标题文本颜色

如何更改以下首选项 XML 中标题和摘要的颜色: 如何更改以下首选项 XML 中 title 和 summary 的颜色: <EditTextPreference android:key="username" android:title="Your Name" android:summary="Please provide your username." /> 我在我的styles.xml中尝试过这个: <style name="SettingsTheme" parent="@style/AppBaseTheme"> <item name="android:textColorPrimary">@color/green</item> <item name="android:textColorSecondary">@color/red</item> <item name="android:textColorTertiary">@color/blue</item> </style> textColorPrimary 更改标题的颜色,但它也会更改工具栏中文本的颜色(我不想要)。 textColorSecond 似乎正确地改变了摘要的颜色。 如何在不影响工具栏文本颜色的情况下更改标题颜色? 您需要像这样显式定义 EditTextPreference 的样式: <style name="SettingsTheme" parent="@style/AppBaseTheme"> <item name="android:editTextPreferenceStyle">@style/MyStyle</item> </style> <style name="MyStyle" parent="@android:style/Preference.DialogPreference.EditTextPreference"> ... </style> 这会将您在 MyStyle 中定义的任何样式仅设置为之前 EditTextPreference 默认样式的位置。 我最近也遇到了同样的问题。刚刚找到了答案。我制作了一个自定义的 EditTextPreference 并在我的代码中执行此操作来更改标题和摘要颜色,我还尝试更改图标色调(颜色)并且它正在工作,您所需要做的就是找到您需要更改的视图并应用您的视图修改如下: class MyEditTextPreference : EditTextPreference { constructor(context: Context) : super(context) constructor(context: Context, attr : AttributeSet?) : super(context, attr) constructor(context: Context, attr: AttributeSet?, i1: Int) : super(context, attr, i1) constructor(context: Context, attr: AttributeSet?, i1: Int, i2: Int) : super(context, attr, i1, i2) override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) (holder.findViewById(android.R.id.title) as TextView).setTextColor(Color.WHITE) (holder.findViewById(android.R.id.icon) as PreferenceImageView).imageTintList = ColorStateList.valueOf(Color.WHITE) (holder.findViewById(android.R.id.summary) as TextView).setTextColor(ResourcesCompat.getColor(context.resources, R.color.test_color, null)) } } 在你的 xml 文件中你必须使用这个 <mypackage.MyEditTextPreference app:icon="@drawable/ic_test" app:key="testKey" app:title="@string/testString" app:useSimpleSummaryProvider="true" /> 注1: 我使用了一个简单的摘要提供程序,但您可以使用您想要的任何摘要。 注2: 这些代码是用 kotlin 编写的,但您可以简单地将它们转换为 Java。 我认为最简单的方法是子类化 EditTextPreference 并在 onCreateView() 或 onBindView() 中调整标题颜色。 public class MyEditTextPreference extends EditTextPreference { // constructors omitted @Override protected void onBindView(View view) { TextView titleView = (TextView) view.findViewById(android.R.id.title); int color = getContext().getResources().getColor(R.color.preference_title); titleView.setTextColor(color); } } 然后在您的首选项 XML 中,您将使用您的类(完全限定名称): <com.package.MyEditTextPreference android:key="username" android:title="Your Name" android:summary="Please provide your username." />

回答 3 投票 0

我无法使工具栏看起来是浮动的

早上好,我正在使用 Android Studio 并尝试使工具栏在底部带有高程阴影,使其看起来像是浮动的,但这不起作用,没有显示阴影。

回答 1 投票 0

360dp 的布局在不同手机上看起来有所不同

我的 Android 应用程序中有一个文件夹,标记为:values-sw360dp 我在不同的手机上测试过,最小宽度是360: 配置config = context.getResources().getConfiguration(); 整数x...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.