我想为linearLayout创建一个边框.所以我决定创造一个形状.我希望边框有一个渐变.以下不是这样做的.它填充矩形,然后创建笔画.我不想要一个填充的矩形,只需要一个笔画.我想将渐变应用于笔画.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="360"
android:centerColor="#e95a22"
android:endColor="#ff00b5"
android:gradientRadius="360"
android:startColor="#006386"
android:type="sweep" />
<stroke
android:width="2dp"
android:color="#ff207d94" />
</shape>
Run Code Online (Sandbox Code Playgroud) 我刚遇到一个我不知道如何解决的问题.它看起来很傻但我找不到解决方法.
我在android中有一个带有几个EditText的表单,当你提交表单时,它检查那些EditText,如果他们有错误的数据,我将EditText更改为红色边框(应用9patch图像).
myEditText.setBackgroundResource(R.drawable.edittext_red);
Run Code Online (Sandbox Code Playgroud)
问题是,我想在用户更改EditText时恢复android的默认样式,但我不知道该怎么做.如果我做:
myEditText.setBackgroundResource(0);
Run Code Online (Sandbox Code Playgroud)
它会删除所有内容,而这不是我想要的.
谢谢!
android nine-patch android-edittext android-resources android-drawable
我试图用OvalShape绘制自定义ShapeDrawable,填充白色和灰色边框.我创建了一个这样的drawable:
ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
drawable.getPaint().setColor(Color.GRAY);
drawable.getPaint().setStyle(Style.STROKE);
drawable.getPaint().setStrokeWidth(getPixels(5));
drawable.getPaint().setAntiAlias(true);
Run Code Online (Sandbox Code Playgroud)
但结果是:角落问题

这个想法是以编程方式创建这样的形状,但具有不同的颜色:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<corners android:radius="10dip"/>
<stroke android:color="#FF0000" android:width="5dip"/>
<solid android:color="@android:color/transparent"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
怎么能解决这个问题?
Android中的可绘制形状是否适用于fill_parent它的大小?
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
<size
android:width="fill_parent"
android:height="fill_parent"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
编辑
这是ImageButton视图的背景.我希望按钮的图标后面有一个圆圈,但我并不总是知道按钮的大小(每个布局的大小不同).
在我的应用程序中,我使用XML定义的垂直虚线.
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="90"
android:toDegrees="90">
<shape
android:shape="line">
<stroke
android:width="1dp"
android:color="@color/light_gray"
android:dashWidth="2dp"
android:dashGap="4dp"
/>
</shape>
Run Code Online (Sandbox Code Playgroud)
当我在Android Studio中挑选我的布局时,线条会正确地呈现点状,但是当我在真实设备上运行应用程序时出现问题.这条线很稳固,没有间隙.你知道问题出在哪里吗?我尝试了很多不同的设备,包括那些运行最新4.3 Android的设备.它看起来无处不在:/
我有一个在大多数设备上运行完美的应用程序.但是,每当我尝试在API <21的设备上运行我的应用程序时,我都会遇到FATAL异常.
这是日志:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aceinteract.sleak/com.aceinteract.sleak.activity.LoginRegisterActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$700(ActivityThread.java:158)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:846)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at …Run Code Online (Sandbox Code Playgroud) xml android android-resources android-drawable android-vectordrawable
我将导航抽屉图标更改为自定义图标时遇到问题.我目前不得不实现标准的抽屉图标,顶部有3条水平线,但现在我想用我的自定义抽屉图标替换它.
这就是我mDrawerToggle现在的样子:
mDrawerToggle=new ActionBarDrawerToggle(this,
mDrawerLayout,
R.drawable.app_icon,
R.string.drawer_open) {
// My code
};
Run Code Online (Sandbox Code Playgroud) android android-actionbar android-drawable android-navigation android-actionbaractivity
Android studio 2.0 Preview 3b
你好,
我创建了以下布局,我想用它作为我的应用程序的背景.我正在使用layer-list,我想在两个地方展示一碗豌豆.在预览中一切看起来都不错,但是当我在genymotion或一些廉价的中国设备上运行时,图像会在屏幕上延伸.但是,在Android AVD上,一切看起来都不错,在我的Nexus 5(真实设备)上一切正常.
这就是我想要的,这就是它在AVD和Nexus 5中的显示方式.你可以看到没有问题.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:centerX="0.5"
android:centerY="0.3"
android:endColor="#08e25b"
android:gradientRadius="300dp"
android:startColor="#b7e9c9"
android:type="radial" />
</shape>
</item>
<item
android:width="48dp"
android:height="48dp"
android:left="350dp"
android:top="400dp">
<bitmap android:src="@drawable/peas" />
</item>
<item
android:width="68dp"
android:height="68dp"
android:drawable="@drawable/peas"
android:left="-20dp"
android:top="480dp" />
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我已将peas.png文件放入drawable-nodpi,只需添加宽度和高度layer-list
当我运行genymotion和一些便宜的智能设备时,我得到以下内容:

Run Code Online (Sandbox Code Playgroud)Just quick summary. Nexus 5 real device and AVD devices works ok Genymotion and cheap smart devices doesn't display correctly
我对我应该相信的事感到困惑.我也尝试使用位图来查看是否会产生任何影响.
非常感谢任何建议.
我已经从Google IO Schedule应用程序源(https://github.com/google/iosched)复制了一个文件
selected_navdrawer_item_background.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/backgroundColor">
<shape>
<solid android:color="#12000000" />
</shape>
</item>
<item android:drawable="?android:selectableItemBackground"/>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我想用它来突出显示NavigationDrawer中当前选定的项目.我的问题是,当我启动我的应用程序时,它会引发异常.
这是我认为的重要路线.
caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #22:
<item> tag requires a 'drawable' attribute or child tag defining a drawable
Run Code Online (Sandbox Code Playgroud)
第22行是这一行
<item android:drawable="?android:selectableItemBackground"/>
Run Code Online (Sandbox Code Playgroud)
我不知道问题是什么,我从源头复制了它而没有调整它.它在他们的应用程序中运行良好.
我试图改变?android:selectableItemBackground到?attr/selectableItemBackground,但它给了我同样的异常.我似乎无法找到任何其他建议的解决方案.
如果有人知道是什么导致了这一点,请帮助我.
这是我的启动画面.我正在使用一个组装我的背景layer-list.如何将文本添加到图层列表?
android ×10
android-drawable ×10
layer-list ×2
xml-drawable ×2
android-xml ×1
dotted-line ×1
drawable ×1
genymotion ×1
nine-patch ×1
xml ×1