https://www.gravatar.com/avatar/7a0c24f697ea1587001c36d00039b60f?s=240&d=mp

PreferenceCategory背景颜色设置

大家可能遇到,PreferenceCategory默认是黑色背景,如何我们更换了PreferenceScreen的背景,那么这种分隔栏看上去很丑,那么怎么更改背景呢?我们可以通过自定义VIEW来实现。 代码如下:

public class MyPreferenceCategory extends PreferenceCategory {
public MyPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
view.setBackgroundColor(Color.parseColor("#b0000000"));
if (view instanceof TextView) {
TextView tv = (TextView) view;
tv.setTextSize(16);
tv.setTextColor(Color.BLACK);
}
}

使用的时候:

<com.blogchen.myview.MyPreferenceCategory android:title="其他" >
<PreferenceScreen
android:key="blog_"
android:summary="作者博客地址"
android:title="访问博客" >
<intent
android:action="android.intent.action.VIEW"
android:data="http://www.ithome.me" />
</PreferenceScreen>
</com.blogchen.myview.MyPreferenceCategory>

python2.7命令行中文乱码

关于python在命令行模式下输出中文乱码的问题。关键还是需要在头部加上

# -- coding: GBK --

这句,但是可能发现加了这句还是乱码。

#filename:hw.py
print "你好,世界!"
raw_input('请按回车键关闭窗口');

原因在于你的代码中的中文是在加入这句之前写的。所以加入这句代码后。对代码中的中文重新输入。然后保存。这是因为文件保存格式的问题。

Scrollview嵌套HorizontalScrollView导致横向滑动卡顿现象解决

也许会有人遇到,在这里说下解决方法。方便以后有人纠结这个问题。开发中经验会遇到滑动里面嵌入滑动的问题,但是这种情况下触摸事件就会发生冲突。导致滑动非常卡,甚至出现程序停止响应。这种情况下我们一般需要重写view。下面给出重新scrollview的方法

public class CustomScrollView extends ScrollView {

private GestureDetector mGestureDetector;

View.OnTouchListener mGestureListener;

@SuppressWarnings("deprecation")
public CustomScrollView(Context context,AttributeSet attrs) {

super(context,attrs);

mGestureDetector= new GestureDetector(new YScrollDetector());

setFadingEdgeLength(0);

}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev) &amp;&amp; mGestureDetector.onTouchEvent(ev);
}

// Return false if we're scrolling in the x direction

class YScrollDetector extends SimpleOnGestureListener {

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if(Math.abs(distanceY) &gt; Math.abs(distanceX)) {
return true;
}
return false;
}
}
}

使用的时候使用这个自定义的控件就可以了。