我想设计一个看起来像下图中的搜索条.
通过使用默认搜索条,我将得到这样的东西:
所以我需要的是只改变颜色.我不需要额外的款式.是否有任何直接的方法来做这个或我应该建立我的自定义drawable.?
我尝试构建自定义的一个,但我无法得到如上所示的确切的一个.使用自定义drawable后,我得到的如下所示:
如果我需要构建自定义的那个,那么请建议如何减少进度线的宽度以及形状.
我的自定义实现:
background_fill.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:centerColor="#FF555555"
android:endColor="#FF555555"
android:startColor="#FF555555" />
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
Run Code Online (Sandbox Code Playgroud)
progess_fill.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:centerColor="#FFB80000"
android:endColor="#FFFF4400"
android:startColor="#FF470000" />
<corners android:radius="1dp" />
<stroke
android:width="1dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
Run Code Online (Sandbox Code Playgroud)
progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@android:id/background"
android:drawable="@drawable/background_fill"/>
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/progress_fill" />
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
thumb.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" …
Run Code Online (Sandbox Code Playgroud) 搜索栏可以垂直吗?我不是很擅长UI设计,所以如何让搜索栏更漂亮,请给我一些模板和示例.
有一个java.lang.ClassCastException
当我试图让安装的应用程序图标.
这是我的代码.
public Bitmap getAppIcon(String path) {
PackageInfo pi = pm.getPackageArchiveInfo(path, 0);
pi.applicationInfo.sourceDir = path;
pi.applicationInfo.publicSourceDir = path;
Drawable icon = pi.applicationInfo.loadIcon(pm);
Bitmap APKicon = ((BitmapDrawable) icon).getBitmap();
return APKicon;
}
Run Code Online (Sandbox Code Playgroud)
在哪里,pm
是
PackageManager pm = getPackageManager();
Run Code Online (Sandbox Code Playgroud)
并且显示的错误LogCat
是
Caused by: java.lang.ClassCastException: android.graphics.drawable.NinePatchDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
Run Code Online (Sandbox Code Playgroud)
希望有人可以帮助我.
我想为seekbar创建一个自定义拇指,如下所示:
一种解决方案可以是这一种,其中png图片用于绘制拇指.
我认为应该可以只使用xml,因为它与这个拇指非常相似:
thumb.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size android:height="30dp" android:width="30dp"/>
<stroke android:width="18dp" android:color="#882EA5DE"/>
<solid android:color="#2EA5DE" />
<corners android:radius="1dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
只需要添加第二个边框(周围的白色笔划),这样我就可以跳过来管理不同屏幕分辨率的所有图片(hdpi/mdpi/xhdpi/xxhdpi).
我尝试了不同的组合形状"椭圆形"和"环形",但无法得到所需的结果.你怎么能做到的?
我的主要问题是我想增加Seekbar拇指的大小,所以我找到了这篇文章:更改seekbar拇指的大小
从那里说,我可以创建thumb_size.xml并在其中添加以下代码:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<size
android:height="40dp"
android:width="40dp" />
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item android:drawable="@drawable/scrubber_control_normal_holo"/>
Run Code Online (Sandbox Code Playgroud)
但是,然后Android Studio给我错误消息,提示它找不到
scrubber_control_normal_holo
然后我找到了这篇文章:Android:在哪里可以找到RadioButton Drawable?
但是,在我的SDK文件夹/ platforms / android-17 / data / res / drawable文件夹中,我仍然找不到此文件,只能找到类似以下内容的文件:
seek_thumb.xml
但是当我尝试使用它时,它仍然给我错误。