Android UI development issues related to summary

UI design and implementation is an essential part of the development of Android, UI do bad, ugly to the explosion, APP performance no matter how good, it is estimated there will not be many people use it, and if the UI and business logic code that did not deal with the middle will it affect the performance of the APP. To sum up a little, some UI related issues encountered in the development, as well as a solution, available to people in need.

1, Android Full Screen

方法:requestWindowFeature(Window.FEATURE_NO_TITLE);

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

                WindowManager.LayoutParams.FLAG_FULLSCREEN);

2, the difference between the visibility attribute VISIBLE, INVISIBLE, GONE of

Setting method:

XML文件:android:visibility="visible"

Java代码:view.setVisibility(View.VISIBLE);

the difference:

VISIBLE: Setting control visible.

INVISIBLE: Set controls are not visible. Preserve the layout space control possession.

GONE: Set the control to hide. Does not retain control layout space occupied.

3, the upper right corner of the icon created with the drop-down (similar to sweep the micro-channel menu item)

/ ** * Create a menu * /

@Override

public boolean onCreateOptionsMenu(Menu menu) {

menu.add(Menu.NONE, Menu.FIRST+1, 0, getResources().getString(R.string.scan_menu_text)).setIcon(R.drawable.scan_icon_24);

return true;

}

/**

* MenuBuilder use reflection to call the method setOptionalIconsVisible mOptionalIconsVisible set to true, the menu settings icon is visible only to

* Let the menu display icons and text at the same time

* @param featureId

* @param menu

* @return

*/

@Override

public boolean onMenuOpened(int featureId, Menu menu) {

if (menu != null) {

if (menu.getClass().getSimpleName().equalsIgnoreCase("MenuBuilder")) {

try {

Method method = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);

method.setAccessible(true);

method.invoke(menu, true);

} catch (Exception e) {

e.printStackTrace ();

}

}

}

return super.onMenuOpened(featureId, menu);

}

/**

* Click on the event menu

*/

@Override

public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item);

switch (item.getItemId()){

case Menu.FIRST+1:

Intent intent = new Intent(RIWarehouseActivity.this, CaptureActivity.class); startActivityForResult(intent, Constant.REQ_QR_CODE);

break;

default: break;

}

return true;

}

 

4, to add controls the border style

Add border_style.xml files drawable directory

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

   <stroke android:width="1dp" android:color="#999999"/>

    <solid android:color="@android:color/transparent"/>

    <corners android:radius="2dp"></corners>

</shape>

Plus android layout property of the control: background = "@ drawable / border_style" can be friends.

5, modify the default style Spinner

Create a file custom_spinner_item_layout.xml

<?xml version="1.0" encoding="utf-8"?>

<! - after the spinner expanded Item Layout ->

<TextView android:id="@+id/spinner_textView" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="3dp" android:textSize="8pt" android:layout_margin="5dp" android:textColor="@color/colorSimpleBlack"></TextView>

activity in use:

arrAdapter = new ArrayAdapter<String>(ScanFirstActivity.this, R.layout.custom_spinner_item_layout, storageDeptsList);storageDeptSpinner.setAdapter(arrAdapter);

6, TextView underlined effect

Resource file:

<resources>

<string name="hello"><u>phone:0123456</u></string>

 </resources> 

Code:

TextView textView = (TextView)findViewById(R.id.tv_test); textView.setText(Html.fromHtml("<u>"+"0123456"+"</u>"));

or

. TextView.getPaint () setFlags (Paint UNDERLINE_TEXT_FLAG.); // underscore textView .getPaint () setAntiAlias ​​(true);. // anti-aliasing 

7, after switching to English, page whiteboard problem

Reason: The text is too long, beyond the page, causing the entire page can not be flushed out. You can modify the text length.

8, page scrolling, and overall problems

Method: add the layout on the outer ScrollView. To adapt them to the parent control that fills the screen. When the contents inside no more than one screen, when not rolling; when the contents of more than one screen, they can scroll through.

A problem might arise is: ScrollView can host only one direct child.

The reason: ScrollView can have only one direct child layout.

Solution: speak multiple sub-layouts wrapped in a layout inside, then this layout as a child of ScrollView layout.

9, Dialog Unable to add window - token null is not for an application wrong solution

AlertDialog dialog = new AlertDialog.Builder(context, R.style.Dialog).create();

Parameters can not use the global context of the application, you must use the current context activity.

10, Android Custom View of PopupLayout

Welcome to the custom pop-up box PopupLayout 

When in use, based on the pop-up box, in the above layout:


Pop-up box on a custom layout file

Use code:

View view=View.inflate(LoginActivity.this,R.layout.popup_fill_host_layout,null);

popupLayout=PopupLayout.init(LoginActivity.this,view);

popupLayout.setUseRadius(true);popupLayout.setWidth(350,true);

popupLayout.setHeight(300,true);

popupLayout.show(PopupLayout.POSITION_CENTER);

//绑定控件

hostPortEdit = view.findViewById(R.id.hostPortEdit);

hostPortEdit.setText(PreferenceUtil.getPreference(getApplication(),"Host"));

hostFillConfirmBtn = view.findViewById(R.id.hostFillConfirmBtn);

hostFillGiveUpBtn = view.findViewById(R.id.hostFillGiveUpBtn);

hostFillConfirmBtn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String newHost = hostPortEdit.getText().toString();

if(!StringUtil.isBlank(newHost)){ PreferenceUtil.setPreference(getApplication(),"Host",newHost);}

Toast.makeText(getApplicationContext(), getResources().getString(R.string.save_success), Toast.LENGTH_SHORT).show(); popupLayout.dismiss();

}});

hostFillGiveUpBtn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

    popupLayout.dismiss();

}});

11,获取自定义view中的控件

View view=View.inflate(LoginActivity.this,R.layout.popup_fill_host_layout,null);

popupLayout=PopupLayout.init(LoginActivity.this,view);

popupLayout.setUseRadius(true);

popupLayout.setWidth(350,true);

popupLayout.setHeight(300,true);

popupLayout.show(PopupLayout.POSITION_CENTER);

//绑定控件

hostPortEdit = view.findViewById(R.id.hostPortEdit);

 

或者

PopUpDialog newDialog = new PopUpDialog(MsgReView.this, R.style.MyDialog);newDialog.setCanceledOnTouchOutside(true);                                                      View view = newDialog.getCustomView();                                                          TextView text1 = (TextView)view.findViewById(R.id.textViewTotal);

12,集成二维码扫描功能

欢迎使用:封装与接入ZXing扫码库

 

码字不易,如果觉得有帮助,一定要给我点赞哟~~

不然信不信我砸了你家灯,半夜偷亲你 ( ̄ε  ̄) !!!

Guess you like

Origin www.cnblogs.com/tonyccc/p/11470098.html