安卓中常用控件遇到问题解决方法(持续更新和发现篇幅)(在textview上加一条线、待续)
2015-07-02 16:25
826 查看
TextView设置最多显示30个字符,超过部分显示...(省略号),有人说分别设置TextView的android:signature="true",并且设置android:ellipsize="end";但是我试了,竟然成功了,供大家参考
[java] view
plaincopy
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxEms="18"
android:singleLine="true"
android:ellipsize="end"
/>
TextView是经常会在listview中作数据显示,然而像很多团购那样,经常会有什么爆款,打折,原价啥,一个textview就这么被一天线强插而入。
一般情况下我们会想都不想直接在布局文件上加那个线。但是往往效果并没那么好看。福利来了,通过J***A代码在上面加一条线。
下面看代码:直接在文字上加一条线岂不是更好...
[java] view
plaincopy
StringBuffer sbf = new StringBuffer("¥"+goods.getValue());//将获取到的商品信息存入到BUFFER里面去
//添加中划线
SpannableString spannable = new SpannableString(sbf);
spannable.setSpan(new StrikethroughSpan(), 0, sbf.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
holder.value.setText(spannable);//给控件赋值
在scrollview中会经常遇到滑动不兼容的,或者第一次进去的时候位置就混乱了,现也贴出代码看下:
[java] view
plaincopy
// 滚动条到顶部去了
mViewFlow.setFocusable(true);
mViewFlow.setFocusableInTouchMode(true);
mViewFlow.requestFocus();
其中的mViewFlow是指定的顶端的控件,只要切换即可
[java] view
plaincopy
// 设置字符的变更
feedBackText.addTextChangedListener(new TextWatcher() {
private CharSequence temp;
private int selectionStart;
private int selectionEnd;
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
temp = s;
}
public void afterTextChanged(Editable s) {
int number = s.length();// 获得长度
textNum.setText("" + number + "/1000");
selectionStart = feedBackText.getSelectionStart();
selectionEnd = feedBackText.getSelectionEnd();
if (temp.length() > 1000) {
s.delete(selectionStart - 1, selectionEnd);
int tempSelection = selectionEnd;
feedBackText.setText(s);
feedBackText.setSelection(tempSelection);// 设置光标在最后
}
}
});
其中的mViewFlow是指定的顶端的控件,只要切换即可 当输入框里面的字符长度变更的时候,后面的也就跟着变更了
设置activity无标题
方法一:
在Manifest.xml中为activity增加属性: android:theme="@android:style/Theme.NoTitleBar"
方法二:
在activity的onCreate()中加入:requestWindowFeature(Window.FEATURE_NO_TITLE);
2.设置activity全屏
方法一:
在Manifest.xml中为activity增加属性: android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
方法二:
代码中增加方法:
public void setFullScreen(boolean isFullScreen) {
if (isFullScreen) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
}
true为设置全屏, false非全屏
[java] view
plaincopy
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxEms="18"
android:singleLine="true"
android:ellipsize="end"
/>
TextView是经常会在listview中作数据显示,然而像很多团购那样,经常会有什么爆款,打折,原价啥,一个textview就这么被一天线强插而入。
一般情况下我们会想都不想直接在布局文件上加那个线。但是往往效果并没那么好看。福利来了,通过J***A代码在上面加一条线。
下面看代码:直接在文字上加一条线岂不是更好...
[java] view
plaincopy
StringBuffer sbf = new StringBuffer("¥"+goods.getValue());//将获取到的商品信息存入到BUFFER里面去
//添加中划线
SpannableString spannable = new SpannableString(sbf);
spannable.setSpan(new StrikethroughSpan(), 0, sbf.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
holder.value.setText(spannable);//给控件赋值
在scrollview中会经常遇到滑动不兼容的,或者第一次进去的时候位置就混乱了,现也贴出代码看下:
[java] view
plaincopy
// 滚动条到顶部去了
mViewFlow.setFocusable(true);
mViewFlow.setFocusableInTouchMode(true);
mViewFlow.requestFocus();
其中的mViewFlow是指定的顶端的控件,只要切换即可
[java] view
plaincopy
// 设置字符的变更
feedBackText.addTextChangedListener(new TextWatcher() {
private CharSequence temp;
private int selectionStart;
private int selectionEnd;
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
temp = s;
}
public void afterTextChanged(Editable s) {
int number = s.length();// 获得长度
textNum.setText("" + number + "/1000");
selectionStart = feedBackText.getSelectionStart();
selectionEnd = feedBackText.getSelectionEnd();
if (temp.length() > 1000) {
s.delete(selectionStart - 1, selectionEnd);
int tempSelection = selectionEnd;
feedBackText.setText(s);
feedBackText.setSelection(tempSelection);// 设置光标在最后
}
}
});
其中的mViewFlow是指定的顶端的控件,只要切换即可 当输入框里面的字符长度变更的时候,后面的也就跟着变更了
设置activity无标题
方法一:
在Manifest.xml中为activity增加属性: android:theme="@android:style/Theme.NoTitleBar"
方法二:
在activity的onCreate()中加入:requestWindowFeature(Window.FEATURE_NO_TITLE);
2.设置activity全屏
方法一:
在Manifest.xml中为activity增加属性: android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
方法二:
代码中增加方法:
public void setFullScreen(boolean isFullScreen) {
if (isFullScreen) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
}
true为设置全屏, false非全屏
相关文章推荐
- HTML5的全局属性
- 关于提交form不刷新的问题
- 在 ASP.NET MVC4 中使用 NInject
- 【Leetcode】House Robber
- ActiveMQ 安装
- 使用苹果的地图与定位
- JQuery+ HightChart+Ajax
- STL学习之deque
- start_kernel----smp_setup_processor_id(以及weak属性)
- 在LAMP环境下搭建JSP动态网页
- phpcms浏览入口端两个访问的示意图
- sql server 2012 数据引擎任务调度算法解析(上)
- arcgis js api前端完成面积测算
- STL学习之deque
- c++ 哪些自定义的数据类型
- 音频信号处理——基音周期
- 信托购买高搜索产品容易推10元[奥运]门槛
- 边走边学Nodejs (基础入门篇)
- Qt 字符串截取大全
- TeeChart替代品,MFC下好用的高速绘图控件-(Hight-Speed Charting)