tools:context =“activityname”布局文件中定activity的渲染上下文

第一步: 首先来看布局文件:activty_about.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
< LinearLayout  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"
     tools:context = "info.Activity.About" >
 
     < TextView
         android:text = "@string/进击e小米出品"
         android:layout_width = "wrap_content"
         android:layout_height = "wrap_content"  />
 
</ LinearLayout >

解释:tools:context="info.Activity.About "这一句不会被打包进APK,ADT的Layout Editor在当前的Layout文件里面设置对应的渲染上下文,说明当前的布局文件所在的渲染上下文是“info.Activity.About”对应的那个activity。

第二步:在AndroidManifest.xml中的设置activity的theme

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<? xml  version = "1.0"  encoding = "utf-8" ?>
< manifest  xmlns:android = "http://schemas.android.com/apk/res/android"
     package = "info.dad.android"  >
 
     < application      
         <!--下面的activity设置了 name="info.Activity.About"的activity的theme-->
         < activity
             android:name = "info.Activity.About"
             android:label = "关于"
             android:theme = "@android:style/Theme.Dialog"  >
         </ activity >
   
     </ application >
 
</ manifest >

在manifest文件中设置了"info.Activity.About" 的theme,那么ADT的Layout Editor会根据这个Theme来渲染当前的Layout。android:theme="@android :style/Theme.Dialog"   将一个Activity显示为能话框模式。那么你在可视化布局管理器里面看到的背景、控件等风格就是Theme.Dialog的样子。仅用于给你看所见即所得的效果而已。

总结:这种显示activity上下文布局的方式,不用写activity java 文件。

附件:常用的系统提供的 android:theme 样式一览表

?
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
26
27
28
29
30
01    android:theme="@android:style/Theme.Dialog"   将一个Activity显示为对话框模式  
   
02    android:theme="@android:style/Theme.NoTitleBar"  无标题栏    
 
03    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  无标题栏,并全屏    
 
04    android:theme="@android:style/Theme.Light"  白色背景    
 
05    android:theme="@android:style/Theme.Light.NoTitleBar"  白色背景,无标题栏    
 
06    android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"  白色背景,无标题栏,全屏    
07    android:theme="@android:style/Theme.Black"  黑色背景    
 
08    android:theme="@android:style/Theme.Black.NoTitleBar"  黑色背景,无标题栏   
  
09    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"    黑色背景,无标题栏,全屏    
10    android:theme="@android:style/Theme.Wallpaper"  用系统桌面为应用程序背景    
 
11    android:theme="@android:style/Theme.Wallpaper.NoTitleBar"  用系统桌面为应用程序背景,无标题栏    
12    android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"  用系统桌面为应用程序背景,无标题栏,全屏    
 
13    android:theme="@android:style/Translucent" 半透明    
 
14    android:theme="@android:style/Theme.Translucent.NoTitleBar" 半透明,无标题栏    
 
15    android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"  半透明,无标题栏,全屏    
 
16    android:theme="@android:style/Theme.Panel"    
 
17    android:theme="@android:style/Theme.Light.Panel"



加入个人理解:

tools:context="activity_name"其实在实际运行是没用的,这个用来让你在设计界面时在下面这个窗口预览一下,顺便指定某个activity的theme


(如果xml布局文件的设置在预览之中没刷新出来,可以再次在这个界面手动点一下就出来了)

(我是菜鸟,不知道这样的理解有没有错,如果有错,还望各位大大的指正)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值