您的位置:首页 > 编程语言

开发常用代码记录

2017-03-17 10:42 337 查看
一、 去掉标题栏

1..在代码里实现 this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏

// 隐藏状态栏

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN;

记住:这句代码要写在setContentView()前面。

2.在清单文件(manifest.xml)里面实现

<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">


这样用可以将整个应用设置成无标题栏,如果只需要在一个Activity设置成一个无标题栏的形式,只要把上面的第三行代码写到某一个Activity里面就可以了。

3.在style.xml文件里定义

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="notitle">
<item name="android:windowNoTitle">true</item>
</style>
</resources>

<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/notitle">


然后面manifest.xml中引用就可以了,这种方法稍麻烦了些。

二、EditText与软件键盘

1.在AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden

2.让EditText失去焦点,使用EditText的clearFocus方法,如下:

EditText edit=(EditText)findViewById(R.id.edit);
edit.clearFocus();


3.强制隐藏Android输入法窗口

EditText edit=(EditText)findViewById(R.id.edit);
InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(),0);


4.EditText始终不弹出软件键盘

EditText edit=(EditText)findViewById(R.id.edit);
edit.setInputType(InputType.TYPE_NULL);


三、获取状态栏高度

int result = 0;
int  resourceId =  context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}


四、TextView添加自动滚动

android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
android:singleLine="true"
android:focusableInTouchMode="true"
android:focusable="true"


五、PopuWindow

背景半透明

/**
*  设置背景的透明度
*
* @param alpha 0.0 - 1.0  1.0表示完全不透明
*/
private void setAlpha(float alpha){
WindowManager.LayoutParams attributes =     getWindow().getAttributes();
attributes.alpha = alpha;
getWindow().setAttributes(attributes);
}


2.点击外部使popuwindow消失

window.setBackgroundDrawable(new ColorDrawable(0x00000000));
window.setOutsideTouchable(true);


仅作为记录,方便日后使用 (持续更新~)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: