我有一个带有透明部分的9patch背景的按钮,但整个按钮有这样的暗色效果,如下所示:
这是按钮xml代码:
<Button
android:id="@+id/login_operator"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="5dp"
android:background="@drawable/white_rounded"
android:drawableRight="@mipmap/arrow_white_down"
android:gravity="left|center_vertical"
android:text="@string/select_operator"
android:textAppearance="?android:attr/textAppearanceMedium" />
Run Code Online (Sandbox Code Playgroud)
以下是此按钮的外观:
这是9补丁背景图片:
这种变暗的效果只发生在Lollipop Android版本上..所以有谁知道这个变暗效果来自哪里?
我有一个这样的图层列表:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/black" />
</shape>
</item>
<item
android:drawable="@drawable/ic_pin"
android:adjustViewBounds="true"
android:scaleType="fitXY" />
</layer-list>
Run Code Online (Sandbox Code Playgroud)
如何以编程方式更改形状和可绘制对象的颜色?
例如,如何#FF0000以@drawable/ic_globe编程方式更改颜色并将可绘制对象更改为?
如何改变AppCompat的高度ProgressBar?
我尝试这个,但没有结果
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:max="100"
android:progress="60"
android:minHeight="20dp"
android:maxHeight="20dp"
android:progressBackgroundTint="@color/pbarbg"
android:theme="@style/LinearProgress" />
Run Code Online (Sandbox Code Playgroud)
而且我有LinearProgress风格
<style name="LinearProgress" parent="Theme.AppCompat.Light">
<item name="colorAccent">@color/pbaractive</item>
</style>
Run Code Online (Sandbox Code Playgroud) android android-appcompat android-progressbar android-xml progress-bar
我有一个布局,代码如下
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->
<LinearLayout
android:id="@+id/layout1"
android:layout_alignParentBottom="true"
android:layout_above="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitStart"
android:layout_marginLeft="5dp"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:src="@drawable/ic_menu_send"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在上面的代码时,键盘秀,我想layout2留在bottom并layout1到go up with keyboard.如果我添加android:windowSoftInputMode="adjustPan|adjustResize"两个布局保持在底部.请帮忙
android android-layout android-softkeyboard android-xml android-studio
我有一个 a 的RecyclerView内部,ConstraintLayout其顶部从a的底部开始textView,其底部向下延伸到父级。我希望此中的项目RecyclerView默认为RecyclerView. 我尝试添加gravity="bottom"并且还尝试了与foregroundGravity和相同的事情layout_gravity。我还尝试添加layout_gravity="bottom"到我的recyclerView项目的布局。尽管如此, 中的所有项目recyclerView仍然默认为顶部。我能做些什么来确保物品在底部吗?这是xml:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/my_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="needed to unlock next coupon"
android:textColor="@color/gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/irrelevant_tv"
android:layout_marginTop="@dimen/spacing_tiny"
android:gravity="center"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/spacing_xl"
android:paddingTop="@dimen/spacing_large"
android:overScrollMode="always"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_constraintTop_toBottomOf="@id/my_tv"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我不想做wrap_content的recyclerView任何,因为否则就不是scrollable(我一直在这3项recyclerView,并根据用户的显示设置,recyclerView可以得到被推离屏幕,这需要我可以滚动)
android android-layout android-xml android-recyclerview android-constraintlayout
我只想将我的设计视为底部导航视图,因此我通过设置tools:showIn="bottom_navigation_view"在menu.xml文件上尝试了以下操作,但它对我的设计视图选项卡没有任何影响
我不想要的菜单视图的图像
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="bottom_navigation_view">
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_home" />
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_dashboard" />
<item
android:id="@+id/navigation_notifications"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/title_notifications" />
</menu>
Run Code Online (Sandbox Code Playgroud)
所以请建议我这样一个有价值的工具:showIn可以工作。
android android-layout android-xml android-menu android-tools-namespace
我正在尝试按照此处使用自定义证书的 Android 文档进行操作。所需的网络配置文件是:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="@raw/extracas"/>
<certificates src="system"/>
</trust-anchors>
</base-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)
我已经创建了 network_security_config.xml 并将引用 a 添加ndroid:networkSecurityConfig="@xml/network_security_config"到我的清单中。我有需要包含的 .crt 文件,但我有两个问题:
我无法在我的原始文件夹中创建目录,当我这样做时,它会在我的文件系统中创建目录,但不在项目中的原始资源目录中。
代替目录,我只是直接在原始文件夹中引用我的 .crt 文件,但是当我尝试引用证书时,这是我的 network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="@raw/cert_cubic_trusted_ca-sha256.crt"/>
<certificates src="system"/>
</trust-anchors>
</base-config>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)我得到一个红色波浪线,错误“缺少 src 资源。”,当我尝试构建时,构建日志输出错误:
AGPBI: {"kind":"error","text":"error: resource raw/certname.crt (aka com.comname.appname:raw/certname.crt) not found.","sources":[{"file":"/Users/205314/project/appname/app/src/main/res/xml/network_security_config.xml","position":{"startLine":5}}],"original":"","tool":"AAPT"}
:app:processDebugResources
:app:processDebugResources FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Failed to process resources, see …Run Code Online (Sandbox Code Playgroud) android android-manifest android-xml android-gradle-plugin android-network-security-config
在ConstraintLayout我需要假设两个视图作为一个组并将该组中心水平放置在父级中,如下图所示:
这是我的 xml 代码:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<TextView
android:id="@+id/view_a"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_orange_dark"
android:gravity="center"
android:text="View A"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@id/view_b"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/view_b"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_light"
android:gravity="center"
android:text="View B"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/view_a"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我已经看过这个答案,但是当两个视图具有相同的宽度时它有效。我的视图宽度不一样,所以Guideline不起作用!
我怎样才能做到这一点?
android centering android-xml android-constraintlayout constraint-layout-chains
我在 res/menu 中为操作栏制作了一个菜单 .xml 文件。这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/search"
android:icon="@android:drawable/ic_search"
app:showAsAction="always"
android:title="Search">
</item>
</menu>
Run Code Online (Sandbox Code Playgroud)
当我尝试运行我的应用程序时,出现以下错误:
AAPT:错误:资源 android:drawable/ic_search 是私有的。
我尝试清理项目,同步Gradle等,disable PrivateResource在Gradle中写入,tools:ignore="PrivateResource"在我的 .xml 中写入。但这些都没有帮助。
感谢你们对我的帮助。
在这里,我试图将整个图像作为卡片视图的背景。但它需要一些空间,如图所示。我试过android:scaleType="centerCrop"和fitXY其他人也试过,但它没有响应。在附加的图像中,紫色表示占用的空白空间。我需要空间需要被背景图像占据。这是我的代码。
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/voilet">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/application_ads_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/app_ads_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<Button
android:id="@+id/application_ads_install_button"
android:layout_width="74dp"
android:layout_height="34dp"
android:layout_marginEnd="48dp"
android:background="@color/voilet"
android:text="@string/application_ads_install"
android:textColor="@color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/application_ads_image"
app:layout_constraintTop_toTopOf="@+id/application_ads_image"
app:layout_constraintVertical_bias="0.674" />
<TextView
android:id="@+id/application_ads_review"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/application_ads_review"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="@+id/application_ads_image"
app:layout_constraintEnd_toStartOf="@+id/application_ads_install_button"
app:layout_constraintHorizontal_bias="0.27"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/application_ads_name"
app:layout_constraintVertical_bias="0.567" />
<TextView
android:id="@+id/application_ads_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Zira"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="@+id/application_ads_image"
app:layout_constraintHorizontal_bias="0.176"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
android android-layout android-xml android-imageview android-cardview
android ×10
android-xml ×10
android-menu ×1
android-network-security-config ×1
android-view ×1
build.gradle ×1
centering ×1
nine-patch ×1
progress-bar ×1