如何在横屏控制软键盘显示一部分

在使用EditText进行文本输入时,若不进行特殊的设置,使用Android自带的软键盘,该软键盘会占用整个界面,那么,如何让键盘只占用屏幕的一部分呢?
Xml代码  收藏代码

  
 <EditText   
        android:id="@+id/text1"   
        android:layout_width="150dip"   
        android:layout_height="wrap_content"  
        android:imeOptions="flagNoExtractUi"/>  


使用android:imeOptinos可对Android自带的软键盘进行一些界面上的设置:
Java代码  收藏代码

  
 android:imeOptions="flagNoExtractUi"  //使软键盘不全屏显示,只占用一部分屏幕  
    同时,这个属性还能控件软键盘右下角按键的显示内容,默认情况下为回车键  
    android:imeOptions="actionNone"  //输入框右侧不带任何提示  
    android:imeOptions="actionGo"    //右下角按键内容为'开始'  
    android:imeOptions="actionSearch"  //右下角按键为放大镜图片,搜索  
    android:imeOptions="actionSend"    //右下角按键内容为'发送'  
    android:imeOptions="actionNext"   //右下角按键内容为'下一步'  
    android:imeOptions="actionDone"  //右下角按键内容为'完成'   


同时,可能EditText添加相应的监听器,捕捉用户点击了软键盘右下角按钮的监听事件,以便进行处理。
Java代码 复制代码 收藏代码

  
 editText.setOnEditorActionListener(new OnEditorActionListener() {   
            @Override  
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {   
                Toast.makeText(MainActivity.this, "text2", Toast.LENGTH_SHORT).show();   
                return false;   
            }   
        });  




补充内容:
1.在string.xml里设置某一部分内容字体颜色

   
<string name="test"><Data><![CDATA[ <b><font color="#ff0000">ABC</font></b> ]]></Data></string>  

注:<b>是字体加粗
使用方法如下:
 textView.setText(getString(R.string.test));


2.图片格式转换:

1.Drawable—>Bitmap

Resources res=getResources();

Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.sample_0);


2.Bitmap---->Drawable

Drawable drawable =new BitmapDrawable(bmp);



3、Drawable → Bitmap

public static Bitmap drawableToBitmap(Drawable drawable) {

       

        Bitmap bitmap = Bitmap.createBitmap(

                                        drawable.getIntrinsicWidth(),

                                        drawable.getIntrinsicHeight(),

                                        drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888

                                                        : Bitmap.Config.RGB_565);

        Canvas canvas = new Canvas(bitmap);

        //canvas.setBitmap(bitmap);

        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());

        drawable.draw(canvas);

        return bitmap;

}


4、从资源中获取Bitmap

Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.pic);


5、Bitmap → byte[]

  
 ByteArrayOutputStream baos = new ByteArrayOutputStream();

    bm.compress(Bitmap.CompressFormat.PNG, 100, baos);

    return baos.toByteArray();   }


6、 byte[] → Bitmap

  
private Bitmap Bytes2Bimap(byte[] b){

                    if(b.length!=0){

                            return BitmapFactory.decodeByteArray(b, 0, b.length);

                    }

                    else {

                            return null;

                    }

          }

猜你喜欢

转载自gzsxt.iteye.com/blog/2144632