css background属性DimEnabled 属性怎么用代码实现

backgroundDimEnabled 属性怎么用代码实现_百度知道
backgroundDimEnabled 属性怎么用代码实现
我有更好的答案
按默认排序
0;item&gt:color/item&transparent&&item name=&&#47:windowIsFloating&quot&lt:windowFrame&quot.6&/
&@/dialog& &style&gt:backgroundDimEnabled&android.Dialog&&#47:background&item name=& parent=&&&/&true&true&lt:windowBackground&quot:color/item name=&item name=&@item name=&quot:backgroundDimAmount&item&gt:style//item&
&item name=&true&lt:windowIsTranslucent&
&T/@item name=&
&/item&&transparent&
&&item&&item&&#47:windowNoTitle&&@null&item&
&true&item name=&style name=&&gt
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁企业信息化
计算机技术
座右铭:世界上有许多好书,但这些书仅仅对那些会读它们的人才是好的——皮丁
Android中将xml布局文件转换为View树的过程解析(上)日联系商易上海电子商务网站建设,了解更多
&  有好几周没写器材了,一方面是因为前几个周末都有些工作,别的也是因为没能找到好的写作标的目标,或者说有些话题
值得分享、写作,可是本身堆集还不敷,没办法只好闷头持续研究了。这段时候一边在写代码,一边也在想Android中
毕竟是如何将R.layout.xxx_view.xml如许的布局文件加载到Android体系的view层次布局中的(即我们常说的view树)。
这时代一方面本身研究了下源码,另一方面也在网上搜刮了下相干文章,发了然2篇很不错的同主题文章,推荐给大师:
http://blog.csdn.net/qinjuning/article/details/7226787&&&http://blog.csdn.net/bigconvience/article/details/。
  我们在开辟中接触的最早的应当算是Activity.setContentView(int resourceId)办法了,我们知道在Activity的onCreate办法
中调用此办法可以把我们供给的根布局文件加载到activity中并显示出来。很天然地我们就从它开端说起吧,空话不久不多说上代码:
* Set the activity content
a layout resource.
The resource will be
* inflated, adding all top-level views to the activity.
* @param layoutResID Resource ID to be inflated.
* @see #setContentView(android.view.View)
* @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
public void setContentView(int layoutResID) { // 实际上其内部都是delegate给了getWindow()办法
getWindow().setContentView(layoutResID);
initActionBar();
* Set the activity content to an explicit view.
This view is placed
* directly into the activity""s view hierarchy.
It can itself be a complex
* view hierarchy.
When calling this method, the layout parameters of the
* specified view are ignored.
Both the width and the height of the view are
* set by default to {@link ViewGroup.LayoutParams#MATCH_PARENT}. To use
* your own layout parameters, invoke
* {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)}
* instead.
* @param view The desired content to display.
* @see #setContentView(int)
* @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
public void setContentView(View view) {
getWindow().setContentView(view);
initActionBar();
* Set the activity content to an explicit view.
This view is placed
* directly into the activity""s view hierarchy.
It can itself be a complex
* view hierarchy.
* @param view The desired content to display.
* @param params Layout parameters for the view.
* @see #setContentView(android.view.View)
* @see #setContentView(int)
public void setContentView(View view, ViewGroup.LayoutParams params) {
getWindow().setContentView(view, params);
initActionBar();
* Add an additional content view to the activity.
Added after any existing
* ones in the activity -- existing views are NOT removed.
* @param view The desired content to display.
* @param params Layout parameters for the view.
public void addContentView(View view, ViewGroup.LayoutParams params) {
getWindow().addContentView(view, params);
initActionBar();
我们可以看到setContentView办法内部都delegate给了getWindow()办法,这里趁便也把addContentView说起了下,setXXX有
调换的意思,addXXX则是往后面在加一个,即以前的还在。紧接着我们看下Activity里的window是咋来的吧,代码如下:
private Window mW // Activity的一个字段
* Retrieve the current {@link android.view.Window} for the activity.
* This can be used to directly access parts of the Window API that
* are not available through Activity/Screen.
* @return Window The current window, or null if the activity is not
public Window getWindow() {
final void attach(Context context, ActivityThread aThread, Instrumentation instr, IBinder token,
Application application, Intent intent, ActivityInfo info, CharSequence title,
Activity parent, String id, NonConfigurationInstances lastNonConfigurationInstances,
Configuration config) {
attach(context, aThread, instr, token, 0, application, intent, info, title, parent, id,
lastNonConfigurationInstances, config);
final void attach(Context context, ActivityThread aThread,
Instrumentation instr, IBinder token, int ident,
Application application, Intent intent, ActivityInfo info,
CharSequence title, Activity parent, String id,
NonConfigurationInstances lastNonConfigurationInstances,
Configuration config) {
attachBaseContext(context);
mFragments.attachActivity(this, mContainer, null);
mWindow = PolicyManager.makeNewWindow(this); // 重视这行代码,这里实际上创建了一个PhoneWindow的实例
mWindow.setCallback(this); // window对象里的Callback接口的实现是Activity
mWindow.getLayoutInflater().setPrivateFactory(this);
if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
mWindow.setSoftInputMode(info.softInputMode);
if (info.uiOptions != 0) {
mWindow.setUiOptions(info.uiOptions);
mUiThread = Thread.currentThread();
mMainThread = aT
mInstrumentation =
mApplication =
mComponent = intent.getComponent();
mActivityInfo =
mEmbeddedID =
mLastNonConfigurationInstances = lastNonConfigurationI
mWindow.setWindowManager(
(WindowManager)context.getSystemService(Context.WINDOW_SERVICE),
mToken, mComponent.flattenToString(),
(info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0);
if (mParent != null) {
mWindow.setContainer(mParent.getWindow());
mWindowManager = mWindow.getWindowManager();
mCurrentConfig =
这里我们趁便申明下Window、Activity、View的差别和接洽:
起首Window是个抽象类,封装了顶层Window样式和行动的策略类,它的实例被用作顶层view加到window manager里面,它供给了
标准的UI策略,如靠山、题目栏、默认的key处理惩罚逻辑等等。在Android体系中有一个独一的实现PhoneWindow,须要window的
时辰就会有一个PhoneWindow的实例被new出来。每个Activity都有一个与之接洽关系的window对象,Activity在其上绘制其UI。
Window对象里又有一个mDecor对象,它是window里的顶层view(也就是说view的层次布局从它开端,它是view树的根)。
更多的申明可以参考这个题目:&/questions/9451755/what-is-an-android-window&。
  接着我们看看上方代码里具体给mWindow对象赋值的代码,先来看看com.android.internal.policy.PolicyManager类:
public final class PolicyManager {
private static final String POLICY_IMPL_CLASS_NAME =
"com.android.internal.policy.impl.Policy";
private static final IPolicy sP
// Pull in the actual implementation of the policy at run-time
Class policyClass = Class.forName(POLICY_IMPL_CLASS_NAME); // 加载class文件
sPolicy = (IPolicy)policyClass.newInstance(); // 按照Class对象,创建个实例
} catch (ClassNotFoundException ex) {
throw new RuntimeException(
POLICY_IMPL_CLASS_NAME + " could not be loaded", ex);
} catch (InstantiationException ex) {
throw new RuntimeException(
POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);
} catch (IllegalAccessException ex) {
throw new RuntimeException(
POLICY_IMPL_CLASS_NAME + " could not be instantiated", ex);
// Cannot instantiate this class
private PolicyManager() {}
// The static methods to spawn new policy-specific objects
public static Window makeNewWindow(Context context) {
return sPolicy.makeNewWindow(context);
public static LayoutInflater makeNewLayoutInflater(Context context) {
return sPolicy.makeNewLayoutInflater(context);
public static WindowManagerPolicy makeNewWindowManager() {
return sPolicy.makeNewWindowManager();
public static FallbackEventHandler makeNewFallbackEventHandler(Context context) {
return sPolicy.makeNewFallbackEventHandler(context);
接着我们看下sPolicy的具体实现类,com.android.internal.policy.impl.Policy.java文件:
public class Policy implements IPolicy {
private static final String TAG = "PhonePolicy";
private static final String[] preload_classes = {
"com.android.internal.policy.impl.PhoneLayoutInflater",
"com.android.internal.policy.impl.PhoneWindow",
"com.android.internal.policy.impl.PhoneWindow¥1",
"com.android.internal.policy.impl.PhoneWindow¥DialogMenuCallback",
"com.android.internal.policy.impl.PhoneWindow¥DecorView",
"com.android.internal.policy.impl.PhoneWindow¥PanelFeatureState",
"com.android.internal.policy.impl.PhoneWindow¥PanelFeatureState¥SavedState",
// For performance reasons, preload some policy specific classes when
// the policy gets loaded.
for (String s : preload_classes) {
Class.forName(s); // 预加载这些类的class文件,以便后面new他们的对象
} catch (ClassNotFoundException ex) {
Log.e(TAG, "Could not preload class for phone policy: " + s);
public Window makeNewWindow(Context context) {
return new PhoneWindow(context); // 至此我们看到了Android体系里真正且独一的Window类型,PhoneWindow
public LayoutInflater makeNewLayoutInflater(Context context) {
return new PhoneLayoutInflater(context); // LayoutInflater接口的实际实现者,今后我们的代码里呈现的类似
// (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)
// 如许的代码,返回的都是此对象。
public WindowManagerPolicy makeNewWindowManager() {
return new PhoneWindowManager();
public FallbackEventHandler makeNewFallbackEventHandler(Context context) {
return new PhoneFallbackEventHandler(context);
至此我们看清楚了Activity中的mWindow对象实际上是PhoneWindow的实例。搞清楚了window对象咋来的,接下来我们可以
解析其setContentView办法了,代码如下:
// This is the top-level view of the window, containing the window decor.
private DecorView mD // window中的顶层view
// This is the view in which the window contents are placed. It is either
// mDecor itself, or a child of mDecor where the contents go.
private ViewGroup mContentP // Android为我们供给的window布局文件中id=@android:id/content的view
// 后面我们会看几个典范的window布局文件
private LayoutInflater mLayoutI
public PhoneWindow(Context context) {
super(context);
mLayoutInflater = LayoutInflater.(context); // 我们在上文中提到的经由过程context.getSystemService实现
@Override
public void setContentView(int layoutResID) {
if (mContentParent == null) { // 第一次调用的时辰履行
installDecor();
} else { // 可以看出setContentView支撑多次调用,只是相当于把之前的view层次布局扔掉,从头再来罢了
mContentParent.removeAllViews();
mLayoutInflater.inflate(layoutResID, mContentParent); // 将我们dev供给的顶层layout文件加到mContentParent里面
final Callback cb = getCallback();
if (cb != null && !isDestroyed()) {
cb.onContentChanged(); // 调用回调函数,一般是Activity或Dialog
@Override
public void setContentView(View view) { // 默认的LayoutParams是MATCH_PARENT,当然你也可以指定
setContentView(view, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
if (mContentParent == null) {
installDecor();
mContentParent.removeAllViews();
mContentParent.addView(view, params);
final Callback cb = getCallback();
if (cb != null && !isDestroyed()) {
cb.onContentChanged();
@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
if (mContentParent == null) {
installDecor();
} // 重视比拟setContentView来说,少了mContentParent.removeAllViews()调用,
// 所以结果就是之前的view层次布局还在,只是新增了一个view
mContentParent.addView(view, params);
final Callback cb = getCallback();
if (cb != null && !isDestroyed()) {
cb.onContentChanged();
接着我们看看installDecor相干的实现:
private void installDecor() {
if (mDecor == null) {
mDecor = generateDecor(); // new一个DecorView(一种特别的FrameLayout)
mDecor.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
mDecor.setIsRootNamespace(true);
if (!mInvalidatePanelMenuPosted && mInvalidatePanelMenuFeatures != 0) {
mDecor.postOnAnimation(mInvalidatePanelMenuRunnable);
if (mContentParent == null) {
mContentParent = generateLayout(mDecor); // 初始化mContentParent
// Set up decor part of UI to ignore fitsSystemWindows if appropriate.
mDecor.makeOptionalFitsSystemWindows();
mTitleView = (TextView)findViewById(com.android.internal.R.id.title);
if (mTitleView != null) {
mTitleView.setLayoutDirection(mDecor.getLayoutDirection());
if ((getLocalFeatures() & (1 && FEATURE_NO_TITLE)) != 0) {
View titleContainer = findViewById(com.android.internal.R.id.title_container);
if (titleContainer != null) {
titleContainer.setVisibility(View.GONE);
mTitleView.setVisibility(View.GONE);
if (mContentParent instanceof FrameLayout) {
((FrameLayout)mContentParent).setForeground(null);
mTitleView.setText(mTitle);
mActionBar = (ActionBarView) findViewById(com.android.internal.R.id.action_bar);
if (mActionBar != null) {
mActionBar.setWindowCallback(getCallback());
if (mActionBar.getTitle() == null) {
mActionBar.setWindowTitle(mTitle);
final int localFeatures = getLocalFeatures();
if ((localFeatures & (1 && FEATURE_PROGRESS)) != 0) {
mActionBar.initProgress();
if ((localFeatures & (1 && FEATURE_INDETERMINATE_PROGRESS)) != 0) {
mActionBar.initIndeterminateProgress();
final ActionBarOverlayLayout abol = (ActionBarOverlayLayout) findViewById(
com.android.internal.R.id.action_bar_overlay_layout);
if (abol != null) {
abol.setOverlayMode(
(localFeatures & (1 && FEATURE_ACTION_BAR_OVERLAY)) != 0);
boolean splitActionBar = false;
final boolean splitWhenNarrow =
(mUiOptions & ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW) != 0;
if (splitWhenNarrow) {
splitActionBar = getContext().getResources().getBoolean(
com.android.internal.R.bool.split_action_bar_is_narrow);
splitActionBar = getWindowStyle().getBoolean(
com.android.internal.R.styleable.Window_windowSplitActionBar, false);
final ActionBarContainer splitView = (ActionBarContainer) findViewById(
com.android.internal.R.id.split_action_bar);
if (splitView != null) {
mActionBar.setSplitView(splitView);
mActionBar.setSplitActionBar(splitActionBar);
mActionBar.setSplitWhenNarrow(splitWhenNarrow);
final ActionBarContextView cab = (ActionBarContextView) findViewById(
com.android.internal.R.id.action_context_bar);
cab.setSplitView(splitView);
cab.setSplitActionBar(splitActionBar);
cab.setSplitWhenNarrow(splitWhenNarrow);
} else if (splitActionBar) {
Log.e(TAG, "Requested split action bar with " +
"incompatible window decor! Ignoring request.");
if ((mResourcesSetFlags & FLAG_RESOURCE_SET_ICON) != 0 ||
(mIconRes != 0 && !mActionBar.hasIcon())) {
mActionBar.setIcon(mIconRes);
} else if ((mResourcesSetFlags & FLAG_RESOURCE_SET_ICON) == 0 &&
mIconRes == 0 && !mActionBar.hasIcon()) {
mActionBar.setIcon(
getContext().getPackageManager().getDefaultActivityIcon());
mResourcesSetFlags |= FLAG_RESOURCE_SET_ICON_FALLBACK;
if ((mResourcesSetFlags & FLAG_RESOURCE_SET_LOGO) != 0 ||
(mLogoRes != 0 && !mActionBar.hasLogo())) {
mActionBar.setLogo(mLogoRes);
// Post the panel
avoid application onCreateOptionsMenu
// being called in the middle of onCreate or similar.
mDecor.post(new Runnable() {
public void run() {
// Invalidate if the panel menu hasn""t been created before this.
PanelFeatureState st = getPanelState(FEATURE_OPTI_PANEL, false);
if (!isDestroyed() && (st == null || st.menu == null)) {
invalidatePanelMenu(FEATURE_ACTION_BAR);
protected DecorView generateDecor() { // 我会在合适的时辰专门解析下DecorView
return new DecorView(getContext(), -1);
protected ViewGroup generateLayout(DecorView decor) {
// Apply data
current theme.
TypedArray a = getWindowStyle();
if (false) {
System.out.println("From style:");
String s = "Attrs:";
for (int i = 0; i & com.android.internal.R.styleable.Window. i++) {
s = s + " " + Integer.toHexString(com.android.internal.R.styleable.Window[i]) + "="
+ a.getString(i);
System.out.println(s);
// 接下来的一大堆代码都是从window的theme中获取属性值,然后调用响应的requestFeature或setFlags办法
mIsFloating = a.getBoolean(com.android.internal.R.styleable.Window_windowIsFloating, false);
int flagsToUpdate = (FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR)
& (~getForcedWindowFlags());
if (mIsFloating) { // 比如这里,若是是floating的(如dialog),则设置layout为WRAP_CONTENT,即非全屏
setLayout(WRAP_CONTENT, WRAP_CONTENT);
setFlags(0, flagsToUpdate);
setFlags(FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR, flagsToUpdate);
if (a.getBoolean(com.android.internal.R.styleable.Window_windowNoTitle, false)) {
requestFeature(FEATURE_NO_TITLE);
} else if (a.getBoolean(com.android.internal.R.styleable.Window_windowActionBar, false)) {
// Don""t allow an action bar if there is no title.
requestFeature(FEATURE_ACTION_BAR);
if (a.getBoolean(com.android.internal.R.styleable.Window_windowActionBarOverlay, false)) {
requestFeature(FEATURE_ACTION_BAR_OVERLAY);
if (a.getBoolean(com.android.internal.R.styleable.Window_windowActionModeOverlay, false)) {
requestFeature(FEATURE_ACTION_MODE_OVERLAY);
if (a.getBoolean(com.android.internal.R.styleable.Window_windowFullscreen, false)) {
setFlags(FLAG_FULLSCREEN, FLAG_FULLSCREEN & (~getForcedWindowFlags()));
if (a.getBoolean(com.android.internal.R.styleable.Window_windowTranslucentStatus,
false)) {
setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS
& (~getForcedWindowFlags()));
if (a.getBoolean(com.android.internal.R.styleable.Window_windowTranslucentNavigation,
false)) {
setFlags(FLAG_TRANSLUCENT_NAVIGATION, FLAG_TRANSLUCENT_NAVIGATION
& (~getForcedWindowFlags()));
if (a.getBoolean(com.android.internal.R.styleable.Window_windowOverscan, false)) {
setFlags(FLAG_LAYOUT_IN_OVERSCAN, FLAG_LAYOUT_IN_OVERSCAN&(~getForcedWindowFlags()));
if (a.getBoolean(com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
setFlags(FLAG_SHOW_WALLPAPER, FLAG_SHOW_WALLPAPER&(~getForcedWindowFlags()));
if (a.getBoolean(com.android.internal.R.styleable.Window_windowEnableSplitTouch,
getContext().getApplicationInfo().targetSdkVersion
&= android.os.Build.VERSION_CODES.HONEYCOMB)) {
setFlags(FLAG_SPLIT_TOUCH, FLAG_SPLIT_TOUCH&(~getForcedWindowFlags()));
a.getValue(com.android.internal.R.styleable.Window_windowMinWidthMajor, mMinWidthMajor);
a.getValue(com.android.internal.R.styleable.Window_windowMinWidthMinor, mMinWidthMinor);
if (a.hasValue(com.android.internal.R.styleable.Window_windowFixedWidthMajor)) {
if (mFixedWidthMajor == null) mFixedWidthMajor = new TypedValue();
a.getValue(com.android.internal.R.styleable.Window_windowFixedWidthMajor,
mFixedWidthMajor);
if (a.hasValue(com.android.internal.R.styleable.Window_windowFixedWidthMinor)) {
if (mFixedWidthMinor == null) mFixedWidthMinor = new TypedValue();
a.getValue(com.android.internal.R.styleable.Window_windowFixedWidthMinor,
mFixedWidthMinor);
if (a.hasValue(com.android.internal.R.styleable.Window_windowFixedHeightMajor)) {
if (mFixedHeightMajor == null) mFixedHeightMajor = new TypedValue();
a.getValue(com.android.internal.R.styleable.Window_windowFixedHeightMajor,
mFixedHeightMajor);
if (a.hasValue(com.android.internal.R.styleable.Window_windowFixedHeightMinor)) {
if (mFixedHeightMinor == null) mFixedHeightMinor = new TypedValue();
a.getValue(com.android.internal.R.styleable.Window_windowFixedHeightMinor,
mFixedHeightMinor);
final Context context = getContext();
final int targetSdk = context.getApplicationInfo().targetSdkV
final boolean targetPreHoneycomb = targetSdk & android.os.Build.VERSION_CODES.HONEYCOMB;
final boolean targetPreIcs = targetSdk & android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
final boolean targetHcNeedsOptions = context.getResources().getBoolean(
com.android.internal.R.bool.target_honeycomb_needs_options_menu);
final boolean noActionBar = !hasFeature(FEATURE_ACTION_BAR) || hasFeature(FEATURE_NO_TITLE);
if (targetPreHoneycomb || (targetPreIcs && targetHcNeedsOptions && noActionBar)) {
addFlags(WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY);
clearFlags(WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY);
if (mAlwaysReadCloseOnTouchAttr || getContext().getApplicationInfo().targetSdkVersion
&= android.os.Build.VERSION_CODES.HONEYCOMB) {
if (a.getBoolean(
com.android.internal.R.styleable.Window_windowCloseOnTouchOutside,
false)) {
setCloseOnTouchOutsideIfNotSet(true);
WindowManager.LayoutParams params = getAttributes();
if (!hasSoftInputMode()) {
params.softInputMode = a.getInt(
com.android.internal.R.styleable.Window_windowSoftInputMode,
params.softInputMode);
if (a.getBoolean(com.android.internal.R.styleable.Window_backgroundDimEnabled,
mIsFloating)) {
/* All dialogs should have the window dimmed */
if ((getForcedWindowFlags()&WindowManager.LayoutParams.FLAG_DIM_BEHIND) == 0) {
params.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
if (!haveDimAmount()) {
params.dimAmount = a.getFloat(
android.R.styleable.Window_backgroundDimAmount, 0.5f);
if (params.windowAnimations == 0) {
params.windowAnimations = a.getResourceId(
com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
// The rest are only done if this wi otherwise,
// the values are inherited
our container.
if (getContainer() == null) {
if (mBackgroundDrawable == null) {
if (mBackgroundResource == 0) {
mBackgroundResource = a.getResourceId(
com.android.internal.R.styleable.Window_windowBackground, 0);
if (mFrameResource == 0) {
mFrameResource = a.getResourceId(com.android.internal.R.styleable.Window_windowFrame, 0);
if (false) {
System.out.println("Background: "
+ Integer.toHexString(mBackgroundResource) + " Frame: "
+ Integer.toHexString(mFrameResource));
mTextColor = a.getColor(com.android.internal.R.styleable.Window_textColor, 0 xFF000000);
// Inflate the window decor.
// 接下来就是按照设定好的features(即窗口风格属性)选择对应的xml文件
int layoutR
int features = getLocalFeatures();
// System.out.println("Features: 0 x" + Integer.toHexString(features));
if ((features & ((1 && FEATURE_LEFT_ICON) | (1 && FEATURE_RIGHT_ICON))) != 0) {
if (mIsFloating) {
TypedValue res = new TypedValue();
getContext().getTheme().resolveAttribute(
com.android.internal.R.attr.dialogTitleIconsDecorLayout, res, true);
layoutResource = res.resourceId;
layoutResource = com.android.internal.R.layout.screen_title_
// XXX Remove this once action bar supports these features.
removeFeature(FEATURE_ACTION_BAR);
// System.out.println("Title Icons!");
} else if ((features & ((1 && FEATURE_PROGRESS) | (1 && FEATURE_INDETERMINATE_PROGRESS))) != 0
&& (features & (1 && FEATURE_ACTION_BAR)) == 0) {
// Special case for a window with only a progress bar (and title).
// XXX Need to have a no-title version of embedded windows.
layoutResource = com.android.internal.R.layout.screen_
// System.out.println("Progress!");
} else if ((features & (1 && FEATURE_CUSTOM_TITLE)) != 0) {
// Special case for a window with a custom title.
// If the window is floating, we need a dialog layout
if (mIsFloating) {
TypedValue res = new TypedValue();
getContext().getTheme().resolveAttribute(
com.android.internal.R.attr.dialogCustomTitleDecorLayout, res, true);
layoutResource = res.resourceId;
layoutResource = com.android.internal.R.layout.screen_custom_
// XXX Remove this once action bar supports these features.
removeFeature(FEATURE_ACTION_BAR);
} else if ((features & (1 && FEATURE_NO_TITLE)) == 0) {
// If no other features and not embedded, only need a title.
// If the window is floating, we need a dialog layout
if (mIsFloating) {
TypedValue res = new TypedValue();
getContext().getTheme().resolveAttribute(
com.android.internal.R.attr.dialogTitleDecorLayout, res, true);
layoutResource = res.resourceId;
} else if ((features & (1 && FEATURE_ACTION_BAR)) != 0) {
layoutResource = com.android.internal.R.layout.screen_action_
layoutResource = com.android.internal.R.layout.screen_
// System.out.println("Title!");
} else if ((features & (1 && FEATURE_ACTION_MODE_OVERLAY)) != 0) {
layoutResource = com.android.internal.R.layout.screen_simple_overlay_action_
// Embedded, so no decoration is needed.
layoutResource = com.android.internal.R.layout.screen_
// System.out.println("Simple!");
mDecor.startChanging(); // 回调点,默示开端。。。
View in = mLayoutInflater.inflate(layoutResource, null); // 将选定的layout文件inflate成view
decor.addView(in, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); // 将其添加到decor中
ViewGroup contentParent = (ViewGroup)findViewById(ID_ANDROID_CONTENT); // 找到体系layout文件中为我们客户端布局预留
if (contentParent == null) {
// 的placeholder,我们的Activity布局将从这里开端。
throw new RuntimeException("Window couldn""t find content container view");
if ((features & (1 && FEATURE_INDETERMINATE_PROGRESS)) != 0) {
ProgressBar progress = getCircularProgressBar(false);
if (progress != null) {
progress.setIndeterminate(true);
// Remaining setup -- of background and title -- that only applies
// to top-level windows.
if (getContainer() == null) {
Drawable drawable = mBackgroundD
if (mBackgroundResource != 0) {
drawable = getContext().getResources().getDrawable(mBackgroundResource);
mDecor.setWindowBackground(drawable);
drawable = null;
if (mFrameResource != 0) {
drawable = getContext().getResources().getDrawable(mFrameResource);
mDecor.setWindowFrame(drawable);
// System.out.println("Text=" + Integer.toHexString(mTextColor) +
// " Sel=" + Integer.toHexString(mTextSelectedColor) +
// " Title=" + Integer.toHexString(mTitleColor));
if (mTitleColor == 0) {
mTitleColor = mTextC
if (mTitle != null) {
setTitle(mTitle);
setTitleColor(mTitleColor);
mDecor.finishChanging(); // 回调点,默示停止了。。。
return contentP // 返回客户端(Activity)布局的parent view
mContentParent被正确初始化后,在setContentView中经由过程mLayoutInflater.inflate(layoutResID, mContentParent);
如许的代码就可以将Activity的布局文件加到全部view层次布局中,如许我们的layout xml就和体系的接洽起来了。
  下面我们看几个前面说到的体系供给的布局文件,针对某个特定的feature属性,代码如下:
&!-- screen_title.xml --&
&LinearLayout xmlns:android="/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true"&
&!-- Popout bar for action modes --&
&ViewStub android:id="@+id/action_mode_bar_stub"
android:inflatedId="@+id/action_mode_bar"
android:layout="@layout/action_mode_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" /&
&FrameLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/windowTitleSize"
style="?android:attr/windowTitleBackgroundStyle"&
&TextView android:id="@android:id/title"
style="?android:attr/windowTitleStyle"
android:background="@null"
android:fadingEdge="horizontal"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" /&
&/FrameLayout&
&FrameLayout android:id="@android:id/content" // 重视这里的共同点,这就是给客户端法度预留的placeholder,mContentParent view
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:foregroundGravity="fill_horizontal|top"
android:foreground="?android:attr/windowContentOverlay" /&
&/LinearLayout&
&!-- screen_simple.xml --&
&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"&
&ViewStub android:id="@+id/action_mode_bar_stub"
android:inflatedId="@+id/action_mode_bar"
android:layout="@layout/action_mode_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" /&
&FrameLayout
android:id="@android:id/content" // 共同点,id都是android:id/content
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foregroundInsidePadding="false"
android:foregroundGravity="fill_horizontal|top"
android:foreground="?android:attr/windowContentOverlay" /&
&/LinearLayout&
  在我们的开辟中,还经常会应用LayoutInflater.inflate办法来将某一个xml文件动态添加到view层次布局中,这种体式格式的确太棒了。
当然为了避免篇幅过长,我会鄙人一篇文章中专门解析下这种景象,敬请等待。终于可以收工了,筹办看西班牙-荷兰的比赛了,哈哈。。。Admin
此页面上的内容需要较新版本的 Adobe Flash Player。}

我要回帖

更多关于 setbackground 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信