标签: xml-drawable

pre v23设备上的Android TextView DrawableTint

我们有什么方法可以在Drawable使用中着色TextView吗?DrawableTint仅适用于API级别23及更高级别.

目前我正在使用a Vertical Linear Layout来达到我的要求.

<LinearLayout style="@style/ChoiceIllustratorIconTextContainerStyle">

  <ImageView
    style="@style/ChoiceIllustratorImageStyle"
    android:contentDescription="@string/cd_university"
    android:src="@drawable/ic_account_balance_white_24dp" />

  <TextView
    style="@style/ChoiceIllustratorTextStyle"
    android:text="@string/ci_text_university" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

它看起来像,在此输入图像描述

Android工作室建议我使用Compound DrawbleTextView来实现这一目标.而且我能够实现它,但我找不到Tint可绘制的方法.

<TextView
   style="@style/ChoiceIllustratorTextStyle"
   android:drawablePadding="4dp"
   android:drawableTop="@drawable/ic_account_balance_white_24dp"
   android:text="@string/ci_text_university" />
Run Code Online (Sandbox Code Playgroud)

android textview xml-drawable

9
推荐指数
4
解决办法
7715
查看次数

Scale Drawable - setImageLevel是否决定了规模?

我已经创建了一个小测试应用程序来尝试缩放drawable.

我在xml中定义了drawable并将其保存为scale_up.xml.我有一个main.xml带有的布局文件ImageView.我android:src="@drawable/scale_up"在ImageView中使用我在xml中创建的drawable.在我的活动中,我myImageView.setImageLevel(some level here)用来设置定义的ImageView的级别main.xml.一切都很好,ImageView显示了scale_up中定义的drawable.

我的困惑如下:

  • 如果级别设置为10000,则更改scaleHeightscaleWidth%in scale_up.xml不会产生可感知的差异
  • 更改setImageLevel(在0到10000之间)的级别会改变图像的大小 - 实际上只能在5000左右看到.scaleHeight和scaleWidth的%值越高,图像越小(取决于值setImageLevel())

我想我的问题是:

  1. 使用是否正确setImageLevel(),在0到10000之间传递一个级别 - 在活动中控制xml文件中定义的drawable的大小?
  2. scaleHeight,scaleWidth和setImageLevel()- 之间的关系是什么,正如我现在看到的那样,我也可以将scaleHeight和scaleWidth设置为100%,然后使用setImageLevel(5000)得到50%缩放图像 - 即增加或减少setImageLevel(0 to 10000)将改变比例 - 制作在scaleHeightscaleWidth%相当没有意义的.

感谢对此的任何澄清,也许是一个如何正确使用scale drawable(在xml中定义)的示例.

android android-ui xml-drawable

8
推荐指数
1
解决办法
1474
查看次数

同一个xml中的Selector,Layer-list和shape/bitmap

我在drawable文件夹内的xml中有这个代码:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <size android:width="90dp" android:height="90dp" />

                <solid android:color="#9933CC" />
                </shape>
            </item>
            <item>
                <bitmap android:gravity="center" android:src="@drawable/main_achievements_synthesis" />
            </item>
        </layer-list>
    </item>
    <item>
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <size android:width="90dp" android:height="90dp" />

                    <solid android:color="#AA66CC" />
                </shape>
            </item>
            <item>
                <bitmap android:gravity="center" android:src="@drawable/main_achievements_synthesis" />
            </item>
        </layer-list>
    </item>

</selector>
Run Code Online (Sandbox Code Playgroud)

我使用它来获得具有2种状态的图像(用作按钮).一切都在模拟器和设备上按预期工作.

我知道我可以创建不同的可绘制xml并进行引用以实现相同的结果.

我刚刚切换到Android Studio,它向我展示了这个消息:Element XXX is not allowed here.它警告我有关Layer-list及其中的所有标签.但是,正如我所说,这段代码工作正常.

我应该将代码切换为单独的XML(知道我只会使用它们一次),还是Android Studio的Inspector Code中的"错误"?

注意:我认为我的代码可以优化,但我还没弄明白怎么做.

android lint xml-drawable android-studio

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

textview下方的行drawable未显示

我有一个textview我想在它下面显示一行.我使用drawableBottom属性来执行此操作.这是我的代码

<TextView
 android:id="@+id/total"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:gravity="right"
 android:text="TextView" 
 android:drawableBottom="@drawable/dividerline"/>
Run Code Online (Sandbox Code Playgroud)

这是我的dividerline.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">

    <stroke
        android:width="70dp"
        android:color="@android:color/black"
        />
    <size
        android:height="1dp"
     />
    <solid
        android:color="@android:color/black"
    />

</shape>
Run Code Online (Sandbox Code Playgroud)

我没有收到错误.只是当我运行我的应用程序时,textview下方没有显示任何行.

有一个误解的drawableBottom属性?期待一些帮助:)

android xml-drawable

7
推荐指数
1
解决办法
8199
查看次数

XML drawable在4.3和4.1.2上具有不同的行为

我有下面的drawable,

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <corners android:radius="3dp"/>
    <padding android:left="1dp" android:right="1dp" android:top="1dp" android:bottom="1dp"/>
     <stroke android:width="1dp" android:color="#e4e4e4"/>

</shape>
Run Code Online (Sandbox Code Playgroud)

"它应该"在背景上设置时绘制边框,实际上它(Android 4.3/goole nexus 7)确实如此,但不幸的是(Android 4.1.2 /三星galaxy tab 10")它只是用颜色填充所有背景

如果有人可以告诉我我做错了什么,或者有人有一个xml drawable for border,我会非常感激:=)

android xml-drawable android-drawable

7
推荐指数
1
解决办法
2389
查看次数

Android - 使用xml drawable制作支票图标

在此输入图像描述

如何使用xml drawable制作这个形状?一直争吵已经很久了,无法完成.

android xml-drawable android-drawable

7
推荐指数
2
解决办法
5259
查看次数

如何在每次点击时更改按钮的图像?

我创建了一个buttonlayout.在Drawable我创建了一个XML file名为的文件夹中btn01_state.将btn01_state.xml被分配给button通过创建我" android:background=@drawable/btn01_state"

现在,button有一个默认的imageimg1.当我click在上面时button,image1变为img2,一旦我释放了点击的鼠标按钮,image2再次变为img1.

我想要做的是,用evey点击改变按钮的图像.

例如,最初btn01有img01

如果按下btn01 ==>将img of btn01设置为img02并保持img02直到再次按下btn01.现在,btn01上有img02.

按下btn01时,将img01设置为btn01.

我希望这更能澄清我想做的事情.

btn_selector:

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

main.xml中

<Button 
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:id="@+id/btn01"
    android:background="@drawable/btn01_state"/>
Run Code Online (Sandbox Code Playgroud)

android button imagebutton xml-drawable

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

使用DrawableCompat在pre-lollipop Drawable中的主题属性?

我已经?attr/colorPrimaryVectorDrawable加载的内容中成功使用了主题属性(例如)VectorDrawableCompat.有没有办法用简单的Drawable包含形状通过DrawableCompat

android xml-drawable android-drawable

6
推荐指数
0
解决办法
240
查看次数

Android LinearLayout:分隔线不会显示

我正在尝试设置要在我的应用程序列表中使用的分隔符。我已经为“diceddivider”制作了 XML 代码,如下所示

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
   android:width="1px"
   android:color="@color/divider_Color"
   />

</shape>
Run Code Online (Sandbox Code Playgroud)

然后我试图将它设置为我的 LinearLayout 的可绘制分隔符,如下所示

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    diceCount = 0;
    diceList = (LinearLayout) this.findViewById(R.id.main_Dice_List);

    diceList.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    diceList.setDividerDrawable(this.getResources().getDrawable(R.drawable.dicedivider));
    diceList.setDividerPadding(5);
    addDice();
}
Run Code Online (Sandbox Code Playgroud)

尽管如此,该应用程序没有显示分隔符。我什至尝试将它直接嵌入到 XML 中,但没有任何运气。

我对 Android 编码很陌生。知道我哪里出错了吗?

android divider android-linearlayout xml-drawable android-drawable

5
推荐指数
1
解决办法
3401
查看次数

当我尝试在 Android Studio 中插入新的矢量资源时,“没有任何内容可显示”

“无内容可显示”错误 - 矢量资源

大家好。所以,最近我将 Android Studio 版本更新到了 4.1(最新版本)。我想像平常一样添加矢量资源,但是..不知何故..图标的预览没有显示。我无法选择矢量资源,甚至无法添加矢量资源。有没有什么办法解决这一问题?或者也许有一种降级版本的方法?太感谢了 :(

android xml-drawable android-studio android-vectordrawable android-studio-4.1

5
推荐指数
1
解决办法
2462
查看次数