189 8069 5689

关于v7android的信息

如何使用android-support-v7-appcompat

综述:通过SDK Manager获取Support Library。

创新互联公司服务项目包括金湖网站建设、金湖网站制作、金湖网页制作以及金湖网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,金湖网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到金湖省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

1、打开Android SDK Manager。

2、在SDK Manager窗口,滚动到Package List的末尾,找到Extra文件夹,如果需要的话打开文件夹显示它的内容。

3、选择Android Support Library项目。

注意:如果你使用的是Android Studio开发,选择并安装Android Support Repository项目而不是Android Support Library项目。

4、点击Install packages按钮。

5、下载完成后,SDK会将Support Library文件安装到你已经存在的Android SDK目录下。

如何在Android Studio中添加RecyclerView-v7支持包

1、打开SDK Manager,在Extras树下找到Android Support Library,下载好支持包。RecyclerView在v7-21版本就出来了。

2、检查app的build.gradle。里面的的v7版本也都是23.2.1

3、打开External Libraries,直接找到类,也没有

4、查看appcompat-v7-23.2.1的属性,里面有源代码引用的位置,在SDK目录下:\extras\android\m2repository\com\android\support\appcompat-v7\23.2.1\appcompat-v7-23.2.1-sources.jar

5、打开上面目录后,发现里面有appcompat-v7,而且里面最新版本就是23.2.1

6、按照第2步的思路,试试直接编译进来是否OK。按照目录结构,在app的build.gradle的dependencies最后添加了一句:

compile ‘com.android.support:recyclerview-v7:23.2.1’

7、Build——Clean Project。等待Clean完毕后,在External Libraries中看到了期待中的recyclerview

8、能导入包了,那就编写代码乐……

在\extras\android\support\v7\recyclerview\libs 目录下发现有android-support-v7-recyclerview.jar。要是上面的方法不行,这就是第二种解决办法了,直接导入到libs中了

android v7包里的Toolbar,怎么定制图标,字体居中的效果

首先使用 Toolbar 来代替ActionBar ,这样我们就能够把ActionBar嵌入到我们的View体系中,然后我们"禁用"系统的status bar,由 DrawerLayout 来处理status bar,最后抽屉部分往上移,或者裁剪掉status bar那一部分。

控制Status bar

在你的values-v21里面添加新的主题,并设置一下属性:

values-v21/themes.xml

style name="AppTheme"

item name="android:windowDrawsSystemBarBackgrounds"true/item

item name="android:statusBarColor"@android:color/transparent/item

/style

这里解释一下:

windowDrawsSystemBarBackgrounds ,将它设置为true,系统将在你的window里面绘制status bar,默认为 TRUE ,之所以要写出来是因为你的theme有可能是继承过来的,确保为true。(在这里小插曲一下,因调试时,总以为注释了这段代码就以为是false,程序员思维害苦了我。另外从命名来看,Android把它称为system bar,可能是为了与能被我们处理的status bar区分开而做的改变。)

statusBarColor 设置为透明是因为我们不再需要系统的status bar,因为我们无法控制它的位置,后面我们将交由 DrawerLayout 来处理。

使用DrawerLayout

首先,你的布局文件应该是和这个类似的:

android.support.v4.widget.DrawerLayout

xmlns:android="url"

android:id="@+id/my_drawer_layout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fitsSystemWindows="true"

!-- Your normal content view --

LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

!-- We use a Toolbar so that our drawer can be displayed

in front of the action bar --

android.support.v7.widget.Toolbar

android:id="@+id/my_awesome_toolbar"

android:layout_height="wrap_content"

android:layout_width="match_parent"

android:minHeight="?attr/actionBarSize"

android:background="?attr/colorPrimary" /

!-- The rest of your content view --

/LinearLayout

!-- The navigation drawer --

ScrimInsetsFrameLayout xmlns:android="rul"

xmlns:app="url"

android:layout_width="304dp"

android:layout_height="match_parent"

android:layout_gravity="left"

android:background="@android:color/white"

android:elevation="10dp"

android:fitsSystemWindows="true"

app:insetForeground="#4000"

!-- Your drawer content --

/ScrimInsetsFrameLayout

/android.support.v4.widget.DrawerLayout

在这里布局里面我们用到了一个的开源类 ScrimInsetsFrameLayout ,它的主要作用就是利用 fitsSystemWindows 的回调方法 fitSystemWindows(Rect insets) 来获取status bar的大小,然后调整画布已达到去掉status bar的效果,所以我们需要在ScrimInsetsFrameLayout 下设置 fitsSystemWindows 为true。当然你也可以不使用这个类,而改用 layout_marginTop 属性来达到效果。

insetForeground 这个属性是ScrimInsetsFrameLayout自带的,表示插入区域的前景色,我们设置为带透明的黑色#4000。别忘了使用这个属性需要添加如下代码到attrs.xml里:

values/attrs.xml

declare-styleable name="ScrimInsetsView"

attr name="insetForeground" format="reference|color" /

/declare-styleable

自此,我们已经实现了将DrawerLayout抽屉的那一部分显示在 Toolbar 和systembar(为了和下面的status bar区分,我们称为system bar)之间了,可是system bar的颜色被我们设置了透明,所以我们接下来要改变status bar的颜色。

改变Status bar的颜色

你可能已经注意到刚才的布局里面 DrawerLayout 的 fitsSystemWindows 属性设置了为true,这是因为我们要在代码里面使用了 DrawerLayout 设置status bar颜色的方法:

// 在这里我们获取了主题暗色,并设置了status bar的颜色

TypedValue typedValue = new TypedValue();

getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);

int color = typedValue.data;

// 注意setStatusBarBackgroundColor方法需要你将fitsSystemWindows设置为true才会生效

DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.my_drawer_layout);

drawerLayout.setStatusBarBackgroundColor(color);

使用ToolBar来代替ActionBar

在代码里面这样设置:

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);

setSupportActionBar(toolbar);

Android Support v4,v7,v13的区别和应用场景

google提供了Android Support Library package 系列的包来保证来高版本sdk开发的向下兼容性,即我们用4.x开发时,在1.6等版本上,可以使用高版本的有些特性,如fragement,ViewPager等,下面,简单说明下这几个版本间的区别:

1.Android Support v4: 这个包是为了照顾1.6及更高版本而设计的,这个包是使用最广泛的,eclipse新建工程时,都默认带有了。

2.Android Support v7: 这个包是为了考虑照顾2.1及以上版本而设计的,但不包含更低,故如果不考虑1.6,我们可以采用再加上这个包,另外注意,v7是要依赖v4这个包的,即,两个得同时被包含。

3.Android Support v13 :这个包的设计是为了android 3.2及更高版本的,一般我们都不常用,平板开发中能用到。


文章题目:关于v7android的信息
转载来于:http://cdxtjz.cn/article/hosegh.html

其他资讯