开发常用代码记录

一、 去掉标题栏

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

  1. 背景半透明
    /**
     *  设置背景的透明度
     *
     * @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);

仅作为记录,方便日后使用 (持续更新~)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值