导航:首页 > 操作系统 > android设置textview边框

android设置textview边框

发布时间:2022-05-30 23:13:07

android multiautocompletetextview 怎么设置边框样式

自己复写下拉的adapter 然后在adapter中加载自己的layout 然后设置layout中TextView为显示不全时滚动

② Android怎么让TextView的边框只有左,上和底部

可以自定义边框的,设置textview的背景就行了。有下面两种方法:

  1. 自己弄一张.9图,只有需求的三个边,然后backgroud设置为该图片;

  2. 自己写个xml的drawable,同样只弄需要的三个边,同样设置为background;

这是比较常用的两个方式吧。

③ 怎么让textview呈现出一个黑色边框

主要有三种方式可以实现:

  1. 带有边框的透明图片

  2. 使用xml的shape设置

  3. 继承TextView覆写onDraw方法。

方法一:

带有透明图片的背景图,只要设置background="#00000"就可以了。

方法二:

通过shape来设置背景图片

首先一个textview_border.xml文件放在drawable文件夹里面

<?xmlversion="1.0"encoding="utf-8"?>

<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle">

<solidandroid:color="#ffffff"/>

<strokeandroid:width="1dip"android:color="#4fa5d5"/>

</shape>

为要添加边框的TextView添加一个background

android:background="@drawable/textview_border"

方法三:

编写一个继承TextView类的自定义组件,并在onDraw事件方法中画边框。

packagecom.example.test;

importandroid.annotation.SuppressLint;

importandroid.content.Context;

importandroid.graphics.Canvas;

importandroid.graphics.Paint;

importandroid.util.AttributeSet;

importandroid.widget.TextView;

@SuppressLint("DrawAllocation")

{

publicBorderTextView(Contextcontext){

super(context);

}

publicBorderTextView(Contextcontext,AttributeSetattrs){

super(context,attrs);

}

privateintsroke_width=1;

@Override

protectedvoidonDraw(Canvascanvas){

Paintpaint=newPaint();

//将边框设为黑色

paint.setColor(android.graphics.Color.BLACK);

//画TextView的4个边

canvas.drawLine(0,0,this.getWidth()-sroke_width,0,paint);

canvas.drawLine(0,0,0,this.getHeight()-sroke_width,paint);

canvas.drawLine(this.getWidth()-sroke_width,0,this.getWidth()-sroke_width,this.getHeight()-sroke_width,paint);

canvas.drawLine(0,this.getHeight()-sroke_width,this.getWidth()-sroke_width,this.getHeight()-sroke_width,paint);

super.onDraw(canvas);

}

}

④ android不用shape怎么给textview描边

stroke:描边
corners:圆角
padding:间隔

Shape的使用如下,制作椭圆形边框textview_bg.xml。

[html] view plain
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="#ffffff" /> <!-- 定义填充的颜色值 -->

⑤ 给textview设置四周边框

您好,1、设置四周边框
<?xml version="1.0"encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000"/>
<stroke android:width="2dip"android:color="#ff000000" />
</shape>
2、只设置底部边框
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the main color -->
<item>
<shape>
<solid android:color="#ffa8abad" />
</shape>
</item>
<!-- This is the line -->
<item android:bottom="2dp">
<shape>
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>

⑥ 怎么给android 设置边框

边框主要是使用shape文件,可以定制左右上下的边框,如果想要隐藏某部分,设置我透明即可。

⑦ android 怎么在程代码中给textview加下边框xml方式我已会了!

给TextView加下边框是不是就是在TetView下面划一条线,如果是这样的话方法有很多:相对布局、透明图片、重写onDraw都可以,我告诉你个及其取巧的方法:
1.tv.setText(Html.fromHtml("<b>附件:</b>"
+ "<a href=\"http://www.google.com\">"+这里填写TextView的值+"</a>"));
2.tv.setMovementMethod(LinkMovementMethod.getInstance());
这是可以跳转的,如果不要执行跳转动作,把第2条语句注释掉

⑧ 如何设置textview的边框

先写drawable里面的xml文件,里面设置shape来设置文本框的特殊效果。

[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- 实心 -->
<solid android:color="@android:color/white" />
<!-- 边框 -->
<stroke
android:width="0.5dp"
android:color="@android:color/black" />
<!-- 圆角 -->
<corners android:radius="3dp" />
<!-- 边距 -->
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
<!-- 渐变 -->
<gradient
android:angle="270"
android:endColor="#FFFF782"
android:startColor="#13C7AF" />

</shape>

基本上常用的就这几种了,要达到很好的效果,你需要重新细致的改写里面的数据。

下面是要用到这个shape的LineLayout,在里面设置了3个TextView,没设置对其的方式,默认是向做靠齐的。

[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/tvbar"
android:text="hello" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/tvbar"
android:text="hello" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/tvbar"
android:text="hello" />

</LinearLayout>

⑨ 怎样在textview中给文字加上边框

可以让TextView填满整个父控件,然后设置与父控件间的边距,再将父控件的背景设置成黑,这样TextView就有一个黑色边框了。。。

阅读全文

与android设置textview边框相关的资料

热点内容
不能修改的pdf 浏览:740
同城公众源码 浏览:475
一个服务器2个端口怎么映射 浏览:283
java字符串ascii码 浏览:62
台湾云服务器怎么租服务器 浏览:462
旅游手机网站源码 浏览:317
android关联表 浏览:930
安卓导航无声音怎么维修 浏览:322
app怎么装视频 浏览:424
安卓系统下的软件怎么移到桌面 浏览:81
windows拷贝到linux 浏览:757
mdr软件解压和别人不一样 浏览:889
单片机串行通信有什么好处 浏览:326
游戏开发程序员书籍 浏览:849
pdf中图片修改 浏览:275
汇编编译后 浏览:480
php和java整合 浏览:835
js中执行php代码 浏览:447
国产单片机厂商 浏览:63
苹果手机怎么设置不更新app软件 浏览:289