android-xml 相关问题

Android项目以多种方式使用XML:定义项目和组件,构建布局,定义动画,创建菜单以及为项目指定资源(静态和动态)。

防止 Snackbar 与 Activity 子 Fragment 的 ConstraintLayout 中的 FloatingActionButton 重叠

这是我当前的设置: 我有一个在根布局(CoordinatorLayout)上注册小吃栏的 BaseActivity: 这是我当前的设置: 我有一个在根布局(CoordinatorLayout)上注册小吃栏的 BaseActivity: <?xml version="1.0" encoding="utf-8"?> <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/snackbar_container" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_dodgeInsetEdges="bottom"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.google.android.material.appbar.AppBarLayout android:id="@+id/app_bar_layout" android:layout_width="match_parent" android:layout_height="wrap_content"> <include layout="@layout/toolbar" /> </com.google.android.material.appbar.AppBarLayout> <include layout="@layout/progressbar_with_text" /> <androidx.fragment.app.FragmentContainerView android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout> 现在我添加一个如下所示的片段: <?xml version="1.0" encoding="utf-8"?> <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"> <androidx.viewpager.widget.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="0dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="parent" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab_save" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/content_save" android:tint="@android:color/white" android:visibility="gone" app:backgroundTint="@color/secondary" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:tint="@android:color/white" app:useCompatPadding="true" tools:ignore="SpeakableTextPresentCheck" tools:visibility="visible" /> </androidx.constraintlayout.widget.ConstraintLayout> 我希望晶圆厂在显示时被小吃栏推起,目前它与小吃栏重叠。 我知道使用 CoordinatorLayout 作为根并将 FloatingActionButton (FAB) 放置在其中可以与属性 app:layout_dodgeInsetEdges="bottom" 配合使用。此设置可确保在显示 Snackbar 时将 FAB 向上推。但是,对于子片段,我无法获得类似的结果。是的,我的设置必须保持原样,因为我有多个彼此不同的片段,并且包含独特样式的 FAB,因此将 FAB 移动到活动级别不是一个选项。 您应该在 BaseActivity 中创建一个方法来显示小吃栏,在该方法中通过其 id 找到 coordinatorLayout。 public void showSnackbar(String message, int duration) { CoordinatorLayout coordinatorLayout = findViewById(R.id.snackbar_container); Snackbar.make(coordinatorLayout, message, duration).show(); } 你的fragment应该能够访问BaseActivity。确保你的activity实现了某个接口,这将允许fragment与activity进行通信。 public class MyFragment extends Fragment { private BaseActivity activity; @Override public void onAttach(Context context) { super.onAttach(context); if (context instanceof BaseActivity) { activity = (BaseActivity) context; } } private void showSnackbar(String message) { activity.showSnackbar(message, Snackbar.LENGTH_SHORT); } }

回答 1 投票 0

在底部对齐 RecyclerView 中的项目

我在 ConstraintLayout 中有一个 RecyclerView,其顶部从 textView 的底部开始,其底部向下延伸到父级。我希望此 RecyclerView 中的项目默认为 ...

回答 3 投票 0

java.lang.UnsupportedOperationException:无法将索引 89 处的值转换为维度:type=0x4

我的应用程序中捕获了以下异常。 12-02 11:49:12.640 10039 940 940 E AndroidRuntime: 致命异常: main 12-02 11:49:12.640 10039 940 940 E AndroidRuntime: 进程: com.an...

回答 1 投票 0

如何使用XML绘制圆角矩形?

这里是绘制具有四个圆角的矩形的标记片段: 这是用于绘制具有四个圆角的矩形的标记片段: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#fff"></solid> <padding android:bottom="5dp" android:left="-1dp" android:right="-1dp" android:top="5dp"></padding> <corners android:radius="2dp"></corners> </shape> 但是如果我只想将一侧(两个角)的角变圆,我该怎么做? 谢谢。 <corners android:bottomLeftRadius="2dp" android:bottomRightRadius="2dp" android:topLeftRadius="2dp" android:topRightRadius="2dp" /> 创建可绘制资源:- <?xml version="1.0" encoding="utf-8"?> <!-- res/drawable/rounded_edittext.xml --> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp"> <solid android:color="#FFFFFF"/> <corners android:bottomRightRadius="15dp" android:bottomLeftRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/> </shape> 设置在任何视图的背景上方。 按照您的要求这样做。 <corners android:bottomLeftRadius="2dp" android:bottomRightRadius="2dp" android:topLeftRadius="0dp" android:topRightRadius="0dp" /> 或 <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" android:topLeftRadius="2dp" android:topRightRadius="2dp" /> 或任何其他显示您运行时间的效果。可以在 xml 文件中将其显示出来。 形状 xmlns:android="http://schemas.android.com/apk/res/android" 机器人:形状=“矩形”> <solid android:color="#FF0000" /> <corners android:radius="16dp" />

回答 4 投票 0

android.view.InflateException:膨胀类 androidx.fragment.app.FragmentContainerView 时出错

我将我的应用程序作为公开测试版发布到 Play 商店。当我使用模拟器运行它或通过 Android Studio 连接手机时,我没有收到任何错误。但是,当我安装该应用程序时...

回答 1 投票 0

应用程序的主题与系统不同时显示网格布局的问题

我的 Gridlayout 元素有问题,无法正确加载。 如果我的 Android 应用程序的主题与手机系统的主题不同,则元素不可见。 我有正常的网格布局...

回答 1 投票 0

为什么我们应该在 Jetpack Compose 中使用 XML 中的字符串?

如果 Compose 的想法是摆脱 XML,为什么仍然建议使用基于 XML 的字符串和字符串资源? 对象字符串 {...} 对象 Sp {...} 对象 Dp {...} 在 .kt 文件中听起来像...

回答 1 投票 0

我正在尝试运行一个应用程序android studio giraffe版本,在布局中不断出现错误粗体线是我的错误

<?xml version="1.0" encoding="utf-8"?> <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" tools:context=".MainActivity"> <LinearLayout android:id="@+id/linearLayout" android:layout_width="1246dp" android:layout_height="783dp" android:gravity="bottom|center|end|top|start" android:orientation="horizontal" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <ImageView android:id="@+id/img_sail" android:layout_width="486dp" android:layout_height="0dp" android:layout_weight="1" android:contentDescription="@string/img_sail" android:scaleType="fitStart" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="@+id/constraintLayout" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/img_sail" /> ** <androidx.constraintlayout.widget.ConstraintLayout** android:id="@+id/constraintLayout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginBottom="3dp" android:layout_weight="1" app:layout_constraintBottom_toTopOf="@+id/textView3" app:layout_constraintEnd_toStartOf="@+id/textView3" app:layout_constraintStart_toStartOf="@+id/textView3" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/txtTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:text="@string/txt_title" android:textSize="48sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/txtDescription" android:layout_width="620dp" android:layout_height="427dp" android:layout_marginStart="24dp" android:layout_marginTop="50dp" android:lineSpacingExtra="8sp" android:text="@string/txt_description" android:textSize="34sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/txtTitle" /> <Button android:id="@+id/btnDate" android:layout_width="602dp" android:layout_height="121dp" android:layout_marginTop="40dp" android:text="@string/btn_date" android:textSize="34sp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.536" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/txtDescription" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="50dp" android:textSize="34sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/constraintLayout" /> </androidx.constraintlayout.widget.ConstraintLayout> 我对 Android Studio 非常陌生,这是我的第二周!请向我解释一下并指导我找到解决方案?我无法运行我的平板电脑专用应用程序!再说一遍,我是新手,想学习解决方案。预先感谢您提供的任何帮助或建议!如果有帮助的话,该应用程序应该看起来像这样?我愿意提供澄清情况所需的任何其他详细信息! 我注意到标签androidx.constraintlayout.widget.ConstraintLayout未关闭,你应该制作像</androidx.constraintlayout.widget.ConstraintLayout>这样的结束标签 我给你的建议是,你应该只学习基本的 android xml,你就会解决这些问题

回答 1 投票 0

如何在android XML中使布局灵活

我在 LinearLayout 中水平排列了 TextView,虽然当前布局在我的设备上运行良好,但当字体大小增加时,我遇到了问题,导致混乱

回答 1 投票 0

触摸目标尺寸太小

我目前面临一个问题,Android Studio 建议增加按钮的触摸目标大小,因为它太小。大多数在线建议建议将 minHeight 设置为 ...

回答 1 投票 0

打开软件键盘时,我看到 CardView 底部有多余的空间 - android

我有以下 xml,但是当打开软件键盘时,我看到 CardView 底部有额外的空间: 我有以下 xml,但是当打开软件键盘时,我看到 CardView 底部有额外的空间: <?xml version="1.0" encoding="utf-8"?> <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:id="@+id/constraintLoginFragment" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/orangePeel_1" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true" tools:context="ir.appinoo.presentation.ui.fragments.login.LoginFragment"> <TextView android:id="@+id/txtTitleLogin" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginTop="20dp" android:layout_marginRight="20dp" android:fontFamily="@font/yekanbakh_regular" android:gravity="right" android:text="@string/login_title" android:textSize="20sp" android:textStyle="bold" app:layout_constraintBottom_toTopOf="@+id/txtDescLogin" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/txtDescLogin" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:fontFamily="@font/yekanbakh_regular" android:gravity="right" android:text="@string/login_title_desc" android:textStyle="bold" app:layout_constraintBottom_toTopOf="@+id/constContainLogin" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/txtTitleLogin" /> <androidx.constraintlayout.widget.ConstraintLayout android:fitsSystemWindows="true" android:id="@+id/constContainLogin" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="15dp" android:orientation="vertical" android:background="@drawable/layout_bg" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/txtDescLogin"> <androidx.core.widget.NestedScrollView android:scrollbars="none" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="30dp" android:layout_marginEnd="30dp" android:fillViewport="true" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"> <androidx.cardview.widget.CardView android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="0dp" android:layout_gravity="center" app:cardCornerRadius="25dp" app:cardElevation="10dp" app:cardUseCompatPadding="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.google.android.material.textfield.TextInputLayout android:id="@+id/txtInputPhone" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="20dp" android:layout_marginRight="5dp" android:hint="@string/hint_login_page" app:boxStrokeColor="#4E4A4A" app:errorEnabled="true" app:shapeAppearanceOverlay="@style/Button4"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/edtPhone" android:layout_width="match_parent" android:layout_height="wrap_content" android:digits="1234567890" android:fontFamily="@font/yekanbakh_regular" android:imeOptions="actionDone" android:inputType="number" android:textColor="@color/black" android:textSize="15sp" android:textStyle="normal" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:id="@+id/txtInputActiveCode" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:hint="@string/active_code" android:visibility="gone" app:boxStrokeColor="#4E4A4A" app:errorEnabled="true" app:shapeAppearanceOverlay="@style/Button4"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/edtActiveCode" android:layout_width="match_parent" android:layout_height="wrap_content" android:digits="1234567890" android:fontFamily="@font/yekanbakh_regular" android:imeOptions="actionDone" android:inputType="number" android:textColor="@color/black" android:textSize="15sp" android:textStyle="normal" /> </com.google.android.material.textfield.TextInputLayout> <TextView android:id="@+id/txtInterval" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:fontFamily="@font/yekanbakh_regular" android:visibility="gone" app:layout_constraintEnd_toEndOf="@id/txtInputActiveCode" app:layout_constraintStart_toStartOf="@id/txtInputActiveCode" app:layout_constraintTop_toBottomOf="@id/txtInputActiveCode" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/txtInputNF" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:hint="@string/name_family" android:visibility="gone" app:boxStrokeColor="#4E4A4A" app:errorEnabled="true" app:shapeAppearanceOverlay="@style/Button4"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/edtNF" android:layout_width="match_parent" android:layout_height="wrap_content" android:fontFamily="@font/yekanbakh_regular" android:imeOptions="actionNext" android:inputType="text" android:textColor="@color/black" android:textSize="15sp" android:textStyle="normal" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:id="@+id/txtInputIdentificationCode" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:hint="@string/identification_code" android:visibility="gone" app:boxStrokeColor="#4E4A4A" app:errorEnabled="true" app:shapeAppearanceOverlay="@style/Button4"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/edtIdentificationCode" android:layout_width="match_parent" android:layout_height="wrap_content" android:digits="1234567890" android:fontFamily="@font/yekanbakh_regular" android:imeOptions="actionDone" android:inputType="number" android:textColor="@color/black" android:textSize="15sp" android:textStyle="normal" /> </com.google.android.material.textfield.TextInputLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="24dp" android:layout_marginTop="20dp" android:layout_marginRight="24dp" android:layout_marginBottom="20dp" android:gravity="center"> <RelativeLayout android:id="@+id/rlBtnLogin" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btnLogIn" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="15dp" android:fontFamily="@font/yekanbakh_regular" android:text="@string/login" android:textAllCaps="false" android:textSize="17sp" app:shapeAppearanceOverlay="@style/Button5" /> <Button android:id="@+id/btnGuest" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="15dp" android:fontFamily="@font/yekanbakh_regular" android:text="@string/text_btn" android:textAllCaps="false" android:textSize="17sp" android:visibility="gone" app:shapeAppearanceOverlay="@style/Button5" /> <Button android:id="@+id/btnNotGuest" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="15dp" android:fontFamily="@font/yekanbakh_regular" android:text="@string/text_btn" android:textAllCaps="false" android:textSize="17sp" android:visibility="gone" app:shapeAppearanceOverlay="@style/Button5" /> <ProgressBar android:id="@+id/prLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" android:visibility="invisible" /> </RelativeLayout> </RelativeLayout> </LinearLayout> </androidx.cardview.widget.CardView> </androidx.core.widget.NestedScrollView> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout> 我编辑如下,干得好: <?xml version="1.0" encoding="utf-8"?> <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:id="@+id/constraintLoginFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/orangePeel_1" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true" tools:context="ir.appinoo.presentation.ui.fragments.login.LoginFragment"> <TextView android:id="@+id/txtTitleLogin" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginTop="20dp" android:layout_marginRight="20dp" android:fontFamily="@font/yekanbakh_regular" android:gravity="right" android:text="@string/login_title" android:textSize="20sp" android:textStyle="bold" app:layout_constraintBottom_toTopOf="@+id/txtDescLogin" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/txtDescLogin" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:fontFamily="@font/yekanbakh_regular" android:gravity="right" android:text="@string/login_title_desc" android:textStyle="bold" app:layout_constraintBottom_toTopOf="@+id/constContainLogin" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/txtTitleLogin" /> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/constContainLogin" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="15dp" android:background="@drawable/layout_bg" android:fitsSystemWindows="true" android:orientation="vertical" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/txtDescLogin"> <androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginStart="30dp" android:layout_marginEnd="30dp" android:fillViewport="true" android:scrollbars="none" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <androidx.cardview.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" app:cardCornerRadius="25dp" app:cardElevation="10dp" app:cardUseCompatPadding="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.google.android.material.textfield.TextInputLayout android:id="@+id/txtInputPhone" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="20dp" android:layout_marginRight="5dp" android:hint="@string/hint_login_page" app:boxStrokeColor="#4E4A4A" app:errorEnabled="true" app:shapeAppearanceOverlay="@style/Button4"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/edtPhone" android:layout_width="match_parent" android:layout_height="wrap_content" android:digits="1234567890" android:fontFamily="@font/yekanbakh_regular" android:imeOptions="actionDone" android:inputType="number" android:textColor="@color/black" android:textSize="15sp" android:textStyle="normal" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:id="@+id/txtInputActiveCode" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:hint="@string/active_code" android:visibility="gone" app:boxStrokeColor="#4E4A4A" app:errorEnabled="true" app:shapeAppearanceOverlay="@style/Button4"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/edtActiveCode" android:layout_width="match_parent" android:layout_height="wrap_content" android:digits="1234567890" android:fontFamily="@font/yekanbakh_regular" android:imeOptions="actionDone" android:inputType="number" android:textColor="@color/black" android:textSize="15sp" android:textStyle="normal" /> </com.google.android.material.textfield.TextInputLayout> <TextView android:id="@+id/txtInterval" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:fontFamily="@font/yekanbakh_regular" android:visibility="gone" app:layout_constraintEnd_toEndOf="@id/txtInputActiveCode" app:layout_constraintStart_toStartOf="@id/txtInputActiveCode" app:layout_constraintTop_toBottomOf="@id/txtInputActiveCode" /> <com.google.android.material.textfield.TextInputLayout android:id="@+id/txtInputNF" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:hint="@string/name_family" android:visibility="gone" app:boxStrokeColor="#4E4A4A" app:errorEnabled="true" app:shapeAppearanceOverlay="@style/Button4"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/edtNF" android:layout_width="match_parent" android:layout_height="wrap_content" android:fontFamily="@font/yekanbakh_regular" android:imeOptions="actionNext" android:inputType="text" android:textColor="@color/black" android:textSize="15sp" android:textStyle="normal" /> </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.textfield.TextInputLayout android:id="@+id/txtInputIdentificationCode" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="5dp" android:layout_marginRight="5dp" android:hint="@string/identification_code" android:visibility="gone" app:boxStrokeColor="#4E4A4A" app:errorEnabled="true" app:shapeAppearanceOverlay="@style/Button4"> <com.google.android.material.textfield.TextInputEditText android:id="@+id/edtIdentificationCode" android:layout_width="match_parent" android:layout_height="wrap_content" android:digits="1234567890" android:fontFamily="@font/yekanbakh_regular" android:imeOptions="actionDone" android:inputType="number" android:textColor="@color/black" android:textSize="15sp" android:textStyle="normal" /> </com.google.android.material.textfield.TextInputLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="24dp" android:layout_marginTop="20dp" android:layout_marginRight="24dp" android:layout_marginBottom="20dp" android:gravity="center"> <RelativeLayout android:id="@+id/rlBtnLogin" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btnLogIn" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="15dp" android:fontFamily="@font/yekanbakh_regular" android:text="@string/login" android:textAllCaps="false" android:textSize="17sp" app:shapeAppearanceOverlay="@style/Button5" /> <Button android:id="@+id/btnGuest" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="15dp" android:fontFamily="@font/yekanbakh_regular" android:text="@string/text_btn" android:textAllCaps="false" android:textSize="17sp" android:visibility="gone" app:shapeAppearanceOverlay="@style/Button5" /> <Button android:id="@+id/btnNotGuest" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="15dp" android:fontFamily="@font/yekanbakh_regular" android:text="@string/text_btn" android:textAllCaps="false" android:textSize="17sp" android:visibility="gone" app:shapeAppearanceOverlay="@style/Button5" /> <ProgressBar android:id="@+id/prLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" android:visibility="invisible" /> </RelativeLayout> </RelativeLayout> </LinearLayout> </androidx.cardview.widget.CardView> </FrameLayout> </androidx.core.widget.NestedScrollView> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

回答 1 投票 0

Android - 如何按显示尺寸的%缩放视图?

我正在使用 Android studio 和 kotlin。我的应用程序有一个 HorizontalScrollView,其中包含一个 LinearLayout,其中包含最多无限数量的 strip_view.xml 布局(每个音频通道 1 个条带...

回答 1 投票 0

添加MaterialCalendarView后,Android studio不显示布局预览

我想设计包含MaterialCalendarView的ConstraintLayout 但是当我将 MaterialCalendarView 添加到 XML 文件时,Android studio 不显示布局预览: 在此输入图像描述 XML 文件:...

回答 1 投票 0

如何访问 AndroidManifest.xml 文件中的 BuildConfig 值?

是否可以从AndroidManifest.xml访问BuildConfig值? 在我的 build.gradle 文件中,我有: 默认配置{ applicationId“com.compagny.product” minSdkVersion 16

回答 7 投票 0

XmlPullParserException 二进制 XML 文件行 #17<vector> 标记需要 viewportWidth > 0

这是这个问题的后续问题: 将 Android 支持库更新到 23.2.0 导致错误:XmlPullParserException 二进制 XML 文件行 #17 标记需要 viewportWidth > 0...

回答 8 投票 0

为什么 Android 自定义对话框会全屏显示

我正在尝试创建自定义对话框。 基本布局(我也尝试过各种修改后的布局): 我正在尝试创建自定义对话框。 基本布局(我也尝试过各种修改后的布局): <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:background="@color/dialogHeaderBackground" android:gravity="center" android:minHeight="@dimen/minHeightDialogTitle" android:text="" android:textStyle="bold" /> <TextView android:id="@+id/message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/title" android:layout_marginTop="5dp" android:text="" /> <LinearLayout android:id="@+id/loutButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_below="@+id/message" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:orientation="horizontal" > <Button android:id="@+id/btnNeutral" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="" /> <Button android:id="@+id/btnNegative" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="" /> <Button android:id="@+id/btnPositive" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="" /> </LinearLayout> </RelativeLayout> Java代码: Dialog dialog = new Dialog(this); // Dialog dialog = new Dialog(this,R.style.Theme_Dialog); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.custom_dialog); Button btnPositive=(Button) dialog.findViewById(R.id.btnPositive); Button btnNegative=(Button) dialog.findViewById(R.id.btnNegative); Button btnNeutral=(Button) dialog.findViewById(R.id.btnNeutral); TextView txvTitle=(TextView)dialog.findViewById(R.id.title); TextView txvMessage=(TextView)dialog.findViewById(R.id.message); ... so on and so forth 我收到以下对话框,该对话框是全屏的,但我不想要: 已经尝试过的解决方案,其结果与上面的屏幕截图相同: Styles.xml 配置 1 | 实现了 Pastebin 代码 Styles.xml 配置 2 | 实现了 Pastebin 代码 Android 开发指南中提供的使用 AlertDialog.Builder 的示例 | 实现的Java代码 我的底层布局都没有使用 MATCH_PARENT 的高度。正如此堆栈溢出中所述 answer 还尝试将窗口设置更改为WRAP_CONTENT,以根据答案此处 | 进行对话在 Pastebin 中实现 Java 代码 还尝试将整个RelativeLayout保留在父级LinearLayout中,请参阅下面的答案中的第3条评论 我唯一能得到像样的对话框是在指定 XML 布局的高度时,就像这样 android:layout_height="150dp" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="150dp" > 指定固定高度时的对话框: 当消息较大时,内容/布局会丢失 当消息较小时,对话框显示得比需要的大,请参见下面的“确定”按钮 不要建议上述(指定固定高度)作为解决方案,因为它效率不高,看起来不太好,也不是动态的,它是静态的。 要指定什么,看起来不错的自定义对话框,也可以自定义? 从线性布局中删除android:layout_alignParentBottom="true"线 <LinearLayout android:id="@+id/loutButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_below="@+id/message" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:orientation="horizontal" > 从上面的代码中删除android:layout_alignParentBottom="true"并检查。 是的,它发生在相对布局中。 在其谷歌docs中明确提到。 请注意,大小之间不能存在循环依赖关系 relativelayout 及其子级的位置。例如,你 不能有高度设置为 WRAP_CONTENT 的relativelayout 和 子项设置为 ALIGN_PARENT_BOTTOM 当您使用对话框时,您必须根据您的要求使用线性布局。 它绝对会为你工作。 进一步的想法可能不适合你,但我只是提一下供参考 您可以使用java代码来制作固定大小的对话框, 或者您可以从布局参数设置布局边距,以便在不同的屏幕尺寸下保持响应能力。 你还可以做一件事, 获取屏幕尺寸 DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int height = metrics.heightPixels; int width = metrics.widthPixels; 你可以计算新的对话框大小并将其设置为@guobao的答案 DisplayMetrics displayMetrics = new DisplayMetrics(); dialog.getWindow().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); params.width = (new width); params.height = (new height); 询问我是否需要任何进一步的规格。 您可以在对话框中设置此代码 DisplayMetrics displayMetrics = new DisplayMetrics(); dialog.getWindow().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); params.width = (the width you want to set); params.height = (the height you want to set); 这是我遇到同样问题时的方法。 我扩展了 DialogFragment(来自 support.v4 lib) 然后充气: @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); final View view = inflater.inflate(R.layout.dialog_whatever, null); builder.setView(view); return builder.create(); } 这是布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rounded_corners" android:padding="20dp"> <TextView android:id="@+id/confirm_dialog_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" android:textColor="@color/black" android:text="@string/are_you_sure_declining_whatever"/> <LinearLayout android:layout_marginTop="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|bottom" android:orientation="horizontal"> <Button android:id="@+id/cancel_action" android:layout_marginRight="10dp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/transparent" android:text="@string/cancel" android:textColor="@color/accent_color"/> <Button android:id="@+id/confirm_action" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/transparent" android:textColor="@color/accent_color" android:text="@string/reject"/> </LinearLayout> </LinearLayout> 这种方法也遵循材料设计指南! 希望对您有帮助 致以诚挚的问候, 佩德罗维奇90

回答 5 投票 0

如何避免在 Android 设备中低于特定高度的不可滚动布局中截断视图

我有一个无法滚动的约束布局,所有视图都必须始终可见。我遇到的问题是,对于高度为 1920 或更低的设备,UI 会变得非常拥挤,并且有些......

回答 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 kotlin 上关闭 include 标签中的 xml 文件

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

回答 1 投票 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

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