小编use*_*308的帖子

wrap_content的背景图像

我创建了一个自定义背景图像,并希望将其用作高度为wrap_content的布局的背景.但是,该布局内容的总高度远小于背景图像的高度.

当我通过android:background ="@ drawable/image"将它设置为XML 背景时,我注意到它显示了图像的整个高度,尽管实际内容的高度要短得多.

有没有办法阻止这种情况发生?

谢谢.

graphics layout android background image

12
推荐指数
1
解决办法
4084
查看次数

按下时将不同的样式应用于按钮

有没有办法在按下按钮时将样式应用于按钮?

如果我在style.xml中有样式:

<resources>
    <style name="test">
        <item name="android:textStyle">bold</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

button.xml中的选择器:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/test_pressed"
              style="@style/test"
          android:state_pressed="true"/>
    <item android:drawable="@drawable/test_focused"
          android:state_focused="true"/>
    <item android:drawable="@drawable/test_normal"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

那么我如何在布局中引用button.xml

<Button
        ...
        android:???="button"/>
Run Code Online (Sandbox Code Playgroud)

谢谢!

android coding-style pressed button

9
推荐指数
3
解决办法
2万
查看次数

自定义按钮:按下时更改样式

我使用样式创建了带阴影的按钮:

<style name="test">
  <item name="android:shadowColor">#FFFFFF</item>
  <item name="android:shadowRadius">1</item>
  <item name="android:shadowDx">1</item>
  <item name="android:shadowDy">1</item>
</style>
Run Code Online (Sandbox Code Playgroud)

这会在按钮文本的正常状态下应用白色阴影.我只是想知道是否有人知道当按钮处于按下状态时是否有一种方法可以移除这个阴影.换句话说,当按钮处于另一个(按下)状态时,有没有办法应用另一种风格?

提前致谢!

编辑

bold.xml:

<resources>
    <style name="bold_text">
        <item name="android:textStyle">bold</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

button.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/test_pressed"
              style="@style/bold_text"
          android:state_pressed="true"/>
    <item android:drawable="@drawable/test_focused"
          android:state_focused="true"/>
    <item android:drawable="@drawable/test_normal"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

我的布局:

<Button
        ...
        android:background="@drawable/button"/>
Run Code Online (Sandbox Code Playgroud)

android state coding-style button

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×3

button ×2

coding-style ×2

background ×1

graphics ×1

image ×1

layout ×1

pressed ×1

state ×1