Android development experience, skills summary (based on Android Studio) (a)

1. Remove the top title bar APP

(1) Open RES -> values -> Styles;
Open style
(2) modify DarkActionBar is NoActionBar.

Default AppTheme:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

After modifying AppTheme:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

2.TextView achieve text automatic carousel achieve

Effect diagram below,
Here Insert Picture Description
two first and most simple animation, written in XML which, of course, can be written in java,
the first in_animation.xml, second out_animation.xml,
the first step: Android which has been TextSwitcher this class, we inherit this class, create a TextView implementation of ViewSwitcher.ViewFactory provided to;
Step two: in order to achieve carousel, of course, is a time to play every once in effect, we can use the timer timer every few seconds to send a message Handler, handler receives the text message to start the update.
With specific reference to https://blog.csdn.net/cpcpcp123/article/details/82049660 , explain in detail.

3.Android TextView font settings

Here Insert Picture Description
Core code

Typeface mtypeface=Typeface.createFromAsset(getAssets(),"huawencaiyunv.TTF");
mTextViewContent.setTypeface(mtypeface);

In this way change the font, the application will take up memory, it is generally not recommended for use in this way, we can see by the following figure, in fact TextView itself comes with several fonts.
Here Insert Picture Description
Specific reference https://blog.csdn.net/mp624183768/article/details/79044063 .

4. Set the size of the color text TextView

(1) The first method is set in activity_main.xml Lee, Java files do not change:

android:text="文字"
android:textSize="字体大小"
android:textColor="颜色"

(2)第二种方法,在MainActivity.java文件里设置,xml不用改:

text.setText("欲穷千里目,更上一层楼");//设置文字内容
text.setTextColor(Color.parseColor("#ff5e9cff"));//设置颜色
text.setTextSize(30);;//设置字体大小

5.ImageView 宽度设定,高度自适应

首先,需要给你的ImageView布局加上android:adjustViewBounds=“true”

<ImageView android:id="@+id/test_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_launcher" />

然后,在代码里设置ImageView.最大宽度和最大高度,因为adjustViewBounds属性只有在设置了最大高度和最大宽度后才会起作用

int screenWidth = getScreenWidth(this);
ViewGroup.LayoutParams lp = testImage.getLayoutParams();
lp.width = screenWidth;
lp.height = LayoutParams.WRAP_CONTENT;
testImage.setLayoutParams(lp);
testImage.setMaxWidth(screenWidth);
testImage.setMaxHeight(screenWidth * 5); //这里其实可以根据需求而定,我这里测试为最大宽度的5倍

具体可参考https://www.cnblogs.com/bcbr/articles/4268276.html

6.使用百度地图SDK获取定位信息

第一步,注册百度账号,在百度地图开放平台新建应用、生成API_KEY;
第二步,下载sdk;
第三步,建立Android Studio工程,配置环境;
第四步,将BaiduLBS_Android.jar加入环境变量(右键,Add As Library),并在app的build.gradle中的android中添加;
第五步,在AndroidManifest.xml文件中声明权限,并在application标签中添加内容;
第六步,测试代码,获取定位信息。
具体过程可参考https://www.jb51.net/article/105089.htm

7.Android设置EditText默认取消焦点

在EditText的父控件中,添加两个属性即可,
如下,

android:focusable="true"
android:focusableInTouchMode="true"

添加后的实例如下,

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:focusable="true"
    android:focusableInTouchMode="true">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:gravity="top"
        android:imeOptions="actionDone"
        android:inputType="text"
        android:padding="4dp"
        android:text="测试文本内容"
        android:textSize="16sp" />
</RelativeLayout>

可参考https://www.jianshu.com/p/83e816600667

8.自定义美观的SeekBar

There are two attributes progressDrawable SeekBar and Thumb, can be used to define the progress bar and the sliding block pattern, .xml file can be customized to achieve the desired aesthetic effect their specific reference
https://blog.csdn.net/sunbinkang / article / details / 78999003 and https://blog.csdn.net/qq_43377749/article/details/84841008

9. copy the text to the system clipboard

(1) Get the clipboard manager:

ClipboardManager mClipboardManager =(ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);

(2) create the object can be stored in ClipData Clipboard (ClipData object contains one or more ClipData.Item objects):

//创建普通字符型ClipData,‘Label’这是任意文字标签
ClipData mClipData =ClipData.newPlainText("Label", "Content");         
// 创建URL型ClipData:
ClipData.newRawUri("Label",Uri.parse("http://www.baidu.com"));
//创建Intent型ClipData:
ClipData.newIntent("Label", intent);

Note that the above three methods create only a ClipData.Item object ClipData object, if you want to add multiple objects to add to ClipData Item should pass ClipData object addItem () method.
(3) ClipData to copy data to the clipboard:

ClipboardManager.setPrimaryClip(ClipData对象);

(4) acquires data from the clipboard ClipData:

ClipboardManager.getPrimaryClip();

Example is as follows,

public class MainActivity extends Activity implements OnClickListener {
    private EditText copy_edt, paste_edt;
    private Button copy_btn, paste_btn;
    //剪切板管理工具类
    private ClipboardManager mClipboardManager;
    //剪切板Data对象
    private ClipData mClipData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mClipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        initViews();
        initListeners();
    }

    private void initViews() {
        this.copy_btn = (Button) findViewById(R.id.copy_btn);
        this.paste_btn = (Button) findViewById(R.id.paste_btn);
        this.copy_edt = (EditText) findViewById(R.id.copy_edt);
        this.paste_edt = (EditText) findViewById(R.id.paste_edt);
    }

    private void initListeners() {
        this.copy_btn.setOnClickListener(this);
        this.paste_btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        String copy = copy_edt.getText().toString().trim();
        switch (v.getId()) {
        case R.id.copy_btn:
            if (TextUtils.isEmpty(copy)) {
                Toast.makeText(getApplicationContext(), "请输入内容!",
                        Toast.LENGTH_SHORT).show();
                return;
            }
            //创建一个新的文本clip对象
            mClipData = ClipData.newPlainText("Simple test", copy);
            //把clip对象放在剪贴板中
            mClipboardManager.setPrimaryClip(mClipData);
            Toast.makeText(getApplicationContext(), "文本已经复制成功!",
                    Toast.LENGTH_SHORT).show();
            break;
        case R.id.paste_btn:
            //GET贴板是否有内容
            mClipData = mClipboardManager.getPrimaryClip();
            //获取到内容
            ClipData.Item item = mClipData.getItemAt(0);
            String text = item.getText().toString();
            paste_edt.setText(text);
            Toast.makeText(getApplicationContext(), "粘贴成功!s",
                    Toast.LENGTH_SHORT).show();
            break;
        }
    }
}

Refer https://blog.csdn.net/true100/article/details/51123599 and https://blog.csdn.net/qq_22078107/article/details/53447905

10. Create a dialog box with three buttons

AlertDialog自带3个按钮PositiveButton、NegativeButton、NeutralButton,可以调用setPositiveButton、setNegativeButton、setNeutralButton三个方法来设置监听器,示例如下:
Dialog dialog = new AlertDialog.Builder(this).setIcon(

     android.R.drawable.btn_star).setTitle("喜好调查").setMessage("你喜欢李连杰的电影吗?")
     .setPositiveButton("很喜欢",new OnClickListener() {
	      @Override
	      public void onClick(DialogInterface dialog, int which) {
		       // TODO Auto-generated method stub
		       Toast.makeText(Main.this, "我很喜欢他的电影。",Toast.LENGTH_LONG).show();
	      }
     })
     .setNegativeButton("不喜欢", new OnClickListener() {
	    @Override
	    public void onClick(DialogInterface dialog, int which) {
		     // TODO Auto-generated method stub
		     Toast.makeText(Main.this, "我不喜欢他的电影。", Toast.LENGTH_LONG).show();
    	}
   })
   .setNeutralButton("一般", new OnClickListener() {
	    @Override
	    public void onClick(DialogInterface dialog, int which) {	
		     // TODO Auto-generated method stub	
		     Toast.makeText(Main.this, "谈不上喜欢不喜欢。", Toast.LENGTH_LONG).show();
    }
   }).create();
   dialog.show();

FIG effect,
Here Insert Picture Description

Published 51 original articles · won praise 184 · views 30000 +

Guess you like

Origin blog.csdn.net/CUFEECR/article/details/103341336