当前位置:   article > 正文

玩味AndroidStudio的NewProject_android studio new project 没有 language

android studio new project 没有 language

这里写图片描述

有没有研究过Android Studio的 那些默认模板? 其中也包括一些新的控件的用法哦?

—————–##首先从最基础的Basic Activity看起 ##——-

若Toolbar不被AppBarLayout 包裹会怎样?
都教是这样的:
这里写图片描述

试一试注释掉:
这里写图片描述!
这里写图片描述!

result:Toolbar和正文的TestView重叠了

不在CoordinatorLayout的FloatingActionButton和Snackbar
FloatingActionButton任然正常显示:

  • Snackbar的用法
fab.setOnClickListener(new View.OnClickListener() {
                           @Override
                           public void onClick(View v) {
                               Snackbar.make(fab, "R.mipmap.ic_launcher", Snackbar.LENGTH_SHORT).setAction("点击", new View.OnClickListener() {
                                   @Override
                                   public void onClick(View v) {
                        只要被点击就会隐藏snackbar
                                       //      Toast.makeText(MainActivity.this, "点击被点击了", Toast.LENGTH_SHORT).show();
                                   }
                               }).setActionTextColor(getResources().getColor(R.color.colorPrimaryDark)).setDuration(Snackbar.LENGTH_INDEFINITE).show();
                           }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

那有没有CoordinatorLayout有什么区别呢?
对于fab有区别
查看源代码:

Having a {@link CoordinatorLayout} in your view hierarchy allows Snackbar to enable certain features, such as swipe-to-dismiss and automatically moving of widgets like {@link FloatingActionButton}.

Snackbar更详细的介绍:

Snackbar使用及其注意事项
(在这里甚至可以修改Snackbar的消息文字的颜色哦)

========================

—————–## Fullscreen Activity ##——-
这里写图片描述
这个界面的特点就是:
1. actionBar ,Navigation ,以及 一个自定义属性的button 隐藏
2. 长按button会有水波纹,然后也会显示到全屏的状态:

首先看清单文件:
这里写图片描述

android:configChanges=”orientation|keyboardHidden|screenSize”
android:configChanges属性

正文:
对android:configChanges属性,一般认为有以下几点:

  1. 不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次

  2. 设置Activity的android:configChanges=”orientation”时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次

  3. 设置Activity的android:configChanges=”orientation|keyboardHidden”时,切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法

但是,自从Android 3.2(API 13),在设置Activity的android:configChanges=”orientation|keyboardHidden”后,还是一样 会重新调用各个生命周期的。因为screen size也开始跟着设备的横竖切换而改变。所以,在AndroidManifest.xml里设置的MiniSdkVersion和 TargetSdkVersion属性大于等于13的情况下,如果你想阻止程序在运行时重新加载Activity,除了设置”orientation”, 你还必须设置”ScreenSize”。

解决方法:
AndroidManifest.xml中设置android:configChanges=”orientation|screenSize“

接下来是布局:
Google 的工程师真的很喜欢用FrameLayout…
Google 的工程师真的很细致还写了注释…..

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0099cc"
    tools:context="com.example.susan.testdemo7.FullscreenActivity">

    <!-- The primary full-screen view. This can be replaced with whatever view
         is needed to present your content, e.g. VideoView, SurfaceView,
         TextureView, etc. -->
    <TextView
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"
        android:text="@string/dummy_content"
        android:textColor="#33b5e5"
        android:textSize="50sp"
        android:textStyle="bold" />

    <!-- This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows. -->
    <FrameLayout
        androi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/223050
推荐阅读
相关标签
  

闽ICP备14008679号