android文本边框
1. 怎么给android 设置边框
1.首先在res目录下新建一个xml文件,类型选择drawable,将自动生一个一个drawable文件(我用的sdk是android 4.1),并生成一个xml文件,在其中写入以下代码:
[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="0.01dp"
android:color="#FFFFFF" />
<padding
android:bottom="1dp"
android:left="0.5dp"
android:right="0.5dp"
android:top="0dp" />
</shape>
2.在要设置边框的控件xml命令里加入:android:background=“@drawable/boder”
2. android程序的输入框四个边都要显示怎么弄
在Android开发中,如果希望输入框四个边都显示,首先需要了解默认情况下,输入框会根据其类型和状态显示不同的边框样式。对于大多数输入框,这种默认设置是满足需求的。
然而,若需进一步自定义边框样式,可以通过设置控件的style属性来实现。在Android的XML布局文件中,可以为输入框设置自定义的样式资源。样式资源可以在styles.xml文件中定义,然后在布局文件中引用。
具体步骤如下:首先,在res/values/styles.xml文件中定义一个新的样式,设置输入框边框的宽度、颜色等属性;然后,在XML布局文件中,为输入框设置这个自定义的style属性。例如:
<EditText android:style="@style/MyInputBorder"></EditText>
其中,“MyInputBorder”是自定义的样式名称,在styles.xml文件中定义如下:
<style name="MyInputBorder">
<item name="android:padding">10dp</item>
<item name="android:background">#FFFFFF</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:shape">rectangle</item>
<item name="android:strokeWidth">2dp</item>
<item name="android:strokeColor">#FF0000</item>
</style>
通过这种方式,可以确保输入框四个边都显示,并且可以根据需求进行调整。值得注意的是,样式定义和引用要保持一致,否则可能会出现样式不生效的情况。
此外,还可以通过代码动态设置输入框的边框样式,例如通过设置View的setStrokeWidth和setStrokeColor方法。这种方法更加灵活,可以根据运行时的状态动态调整边框样式。
总的来说,通过自定义样式或者代码动态设置,可以灵活控制Android输入框的边框显示,满足不同的界面设计需求。
3. Android设计规范 Material Design-Layout
Android设计规范Material Design中的Layout布局要点如下:
度量与边框基准网格:
- 所有组件都与间隔为8dp的基准网格对齐。
- 排版/文字与间隔为4dp的基准网格对齐。
- 工具条中的图标同样与间隔为4dp的基准网格对齐。
边框与间距:
- 移动设备布局模板包含多种屏幕和信息,描述了边框与间距如何应用于屏幕边界和元素。
- 左右各有16dp的垂直边框,带有图标或头像的内容有72dp的左边距,移动设备上有16dp的水平外边距。
- 垂直边距根据不同的布局元素和设计需求,可能取值为24dp、56dp、48dp或72dp等。
触摸目标尺寸:
- 最小的触摸目标尺寸是48dp。
- 在布局中设置图标或头像的边距时,需确保触摸目标不重叠。
增量边框:
- 增量边框定义了一个增量,然后使用几倍于这个增量的数字来决定应用中其它元素的尺寸和位置。
- 增量边框主要应用于桌面应用程序,部分适用于平板设备,较少应用于移动设备。
屏幕宽度与元素宽度:
- 应用于移动设备屏幕的宽度和移动设备、平板设备以及桌面应用程序中UI元素的宽度,需根据具体的屏幕尺寸和设计规范进行调整。
布局模板:
- 移动设备、平板设备和桌面应用程序均有各自的布局模板,这些模板详细展示了边框和边距如何应用于不同的屏幕和元素。
遵循这些规范可以确保Android应用在视觉上的一致性和用户体验的流畅性。
4. android怎么让gridview有边框线
gridview有边框线通过设置里面控件的backgroud,也就是边框。通过shape设置。
下面例子来自于android学习手册,android学习手册包含9个章节,108个例子,源码文档随便看,例子都是可交互,可运行, 源码采用android studio目录结构,高亮显示代码,文档都采用文档结构图显示,可以快速定位。360手机助手中下载,图标上有贝壳。
<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android">
<!--圆角-->
<corners
android:radius="9dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp"
android:bottomLeftRadius="2dp"
android:bottomRightRadius="2dp"/><!--设置圆角半径-->
<!--渐变-->
<gradient
android:startColor="@android:color/white"
android:centerColor="@android:color/black"
android:endColor="@android:color/black"
android:useLevel="true"
android:angle="45"
android:type="radial"
android:centerX="0"
android:centerY="0"
android:gradientRadius="90"/>
<!--间隔-->
<padding
android:left="2dp"
android:top="2dp"
android:right="2dp"
android:bottom="2dp"/><!--各方向的间隔-->
<!--大小-->
<size
android:width="50dp"
android:height="50dp"/><!--宽度和高度-->
<!--填充-->
<solid
android:color="@android:color/white"/><!--填充的颜色-->
<!--描边-->
<stroke
android:width="2dp"
android:color="@android:color/black"
android:dashWidth="1dp"
android:dashGap="2dp"/>
</shape>
5. android 如何去掉edittext上边框
将edittext的style设置成?android:attr/textViewStyle 取消掉默认的样式,在设置background为@null接下来就是一个空空的edittext了(比如http://www.tiecou.com/)
, 在两个edittext中间加一个view,设置background为灰色,宽度match_parent,高度2dip看看。
RelativeLayout xmlns:android="
xmlns:tools="
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@android:color/white"
android:orientation="vertical" >
<EditText
style="?android:attr/textViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:hint="输入用户名"
android:paddingBottom="5dip"
android:paddingTop="5dip" />
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="@android:color/darker_gray" />
<EditText
style="?android:attr/textViewStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:hint="输入密码"
android:inputType="textPassword"
android:paddingBottom="5dip"
android:paddingTop="5dip" />
</LinearLayout>
</RelativeLayout>