Java Code Examples for android.widget.LinearLayout#getChildAt()

The following examples show how to use android.widget.LinearLayout#getChildAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileChooseDialogActivity.java    From SoloPi with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化界面
 */
private void initView() {
    // 标题部分
    upperIcon = findViewById(R.id.file_choose_upper);
    titleText = (TextView) findViewById(R.id.file_choose_title);
    currentDirectoryText = (TextView) findViewById(R.id.file_choose_path);
    createIcon = findViewById(R.id.file_choose_create);

    // List
    dirList = (ListView) findViewById(R.id.file_choose_list);

    // button
    positiveButton = (LinearLayout) findViewById(R.id.file_choose_positive_button);
    positiveBtnText = (TextView) positiveButton.getChildAt(0);
    negativeButton = (LinearLayout) findViewById(R.id.file_choose_negative_button);
    negativeBtnText = (TextView) negativeButton.getChildAt(0);
}
 
Example 2
Source File: MaterialDialog.java    From DialogUtil with Apache License 2.0 6 votes vote down vote up
public void setContentView(View contentView) {
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    contentView.setLayoutParams(layoutParams);
    if (contentView instanceof ListView) {
        setListViewHeightBasedOnChildren((ListView) contentView);
    }
    LinearLayout linearLayout = (LinearLayout) mAlertDialogWindow.findViewById(
            R.id.message_content_view);
    if (linearLayout != null) {
        linearLayout.removeAllViews();
        linearLayout.addView(contentView);
    }
    for (int i = 0; i < (linearLayout != null ? linearLayout.getChildCount() : 0); i++) {
        if (linearLayout.getChildAt(i) instanceof AutoCompleteTextView) {
            AutoCompleteTextView autoCompleteTextView
                    = (AutoCompleteTextView) linearLayout.getChildAt(i);
            autoCompleteTextView.setFocusable(true);
            autoCompleteTextView.requestFocus();
            autoCompleteTextView.setFocusableInTouchMode(true);
        }
    }
}
 
Example 3
Source File: BreadCrumbLayout.java    From RetroMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
public void addCrumb(@NonNull Crumb crumb, boolean refreshLayout) {
    LinearLayout view = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.bread_crumb, this, false);
    view.setTag(mCrumbs.size());
    view.setOnClickListener(this);

    ImageView iv = (ImageView) view.getChildAt(1);
    if (Build.VERSION.SDK_INT >= 19 && iv.getDrawable() != null) {
        iv.getDrawable().setAutoMirrored(true);
    }
    iv.setVisibility(View.GONE);

    mChildFrame.addView(view, new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mCrumbs.add(crumb);
    if (refreshLayout) {
        mActive = mCrumbs.size() - 1;
        requestLayout();
    }
    invalidateActivatedAll();
}
 
Example 4
Source File: AdapterImpl.java    From AsymmetricGridView with MIT License 6 votes vote down vote up
private LinearLayout initializeLayout(LinearLayout layout) {
  // Clear all layout children before starting
  int childCount = layout.getChildCount();
  for (int j = 0; j < childCount; j++) {
    LinearLayout tempChild = (LinearLayout) layout.getChildAt(j);
    linearLayoutPool.put(tempChild);
    int innerChildCount = tempChild.getChildCount();
    for (int k = 0; k < innerChildCount; k++) {
      View innerView = tempChild.getChildAt(k);
      ViewState viewState = (ViewState) innerView.getTag();
      ObjectPool<AsymmetricViewHolder<?>> pool = viewHoldersMap.get(viewState.viewType);
      pool.put(viewState.viewHolder);
    }
    tempChild.removeAllViews();
  }
  layout.removeAllViews();

  return layout;
}
 
Example 5
Source File: MenuFragment.java    From citra_android with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
  View rootView = inflater.inflate(R.layout.fragment_ingame_menu, container, false);

  LinearLayout options = rootView.findViewById(R.id.layout_options);
  for (int childIndex = 0; childIndex < options.getChildCount(); childIndex++)
  {
    Button button = (Button) options.getChildAt(childIndex);

    button.setOnClickListener(this);
  }

  TextView titleText = rootView.findViewById(R.id.text_game_title);
  String title = getArguments().getString(KEY_TITLE);
  if (title != null)
  {
    titleText.setText(title);
  }

  return rootView;
}
 
Example 6
Source File: BreadCrumbLayout.java    From Orin with GNU General Public License v3.0 6 votes vote down vote up
public void addCrumb(@NonNull Crumb crumb, boolean refreshLayout) {
    LinearLayout view = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.bread_crumb, this, false);
    view.setTag(mCrumbs.size());
    view.setOnClickListener(this);

    ImageView iv = (ImageView) view.getChildAt(1);
    if (Build.VERSION.SDK_INT >= 19 && iv.getDrawable() != null) {
        iv.getDrawable().setAutoMirrored(true);
    }
    iv.setVisibility(View.GONE);

    mChildFrame.addView(view, new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mCrumbs.add(crumb);
    if (refreshLayout) {
        mActive = mCrumbs.size() - 1;
        requestLayout();
    }
    invalidateActivatedAll();
}
 
Example 7
Source File: ErrorUrlTest.java    From crosswalk-cordova-android with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    testActivity = this.getActivity();
    containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
    innerContainer = (LinearLayout) containerView.getChildAt(0);
    testView = (CordovaWebView) innerContainer.getChildAt(0);
}
 
Example 8
Source File: BreadCrumbLayout.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
private TextView invalidateActivated(View view, final boolean isActive, final boolean noArrowIfAlone, final boolean allowArrowVisible) {
    int contentColor = isActive ? contentColorActivated : contentColorDeactivated;
    LinearLayout child = (LinearLayout) view;
    TextView tv = (TextView) child.getChildAt(0);
    tv.setTextColor(contentColor);
    ImageView iv = (ImageView) child.getChildAt(1);
    iv.setColorFilter(contentColor, PorterDuff.Mode.SRC_IN);
    if (noArrowIfAlone && getChildCount() == 1)
        iv.setVisibility(View.GONE);
    else if (allowArrowVisible)
        iv.setVisibility(View.VISIBLE);
    else
        iv.setVisibility(View.GONE);
    return tv;
}
 
Example 9
Source File: TileUrlFragment.java    From geopackage-mapcache-android with MIT License 5 votes vote down vote up
/**
 * Find the checkbox in the item row and tell us if it's checked
 * @param itemRow linearLayout containing a checkbox
 * @return true if the checkbox is checked
 */
private boolean isItemRowChecked(LinearLayout itemRow){
    for (int i = 0; i < itemRow.getChildCount(); i++) {
        if(itemRow.getChildAt(i) instanceof CheckBox){
            CheckBox check = (CheckBox) itemRow.getChildAt(i);
            return check.isChecked();
        }
    }
    return false;
}
 
Example 10
Source File: ColorPickerView.java    From timecat with Apache License 2.0 5 votes vote down vote up
public void setColorPreview(LinearLayout colorPreview, Integer selectedColor) {
	if (colorPreview == null)
		return;
	this.colorPreview = colorPreview;
	if (selectedColor == null)
		selectedColor = 0;
	int children = colorPreview.getChildCount();
	if (children == 0 || colorPreview.getVisibility() != View.VISIBLE)
		return;

	for (int i = 0; i < children; i++) {
		View childView = colorPreview.getChildAt(i);
		if (!(childView instanceof LinearLayout))
			continue;
		LinearLayout childLayout = (LinearLayout) childView;
		if (i == selectedColor) {
			childLayout.setBackgroundColor(Color.WHITE);
		}
		ImageView childImage = (ImageView) childLayout.findViewById(R.id.image_preview);
		childImage.setClickable(true);
		childImage.setTag(i);
		childImage.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (v == null)
					return;
				Object tag = v.getTag();
				if (tag == null || !(tag instanceof Integer))
					return;
				setSelectedColor((int) tag);
			}
		});
	}
}
 
Example 11
Source File: NotificationPreferenceActivity.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
private void enableAllChildren(LinearLayout parent, boolean b) {

        try {
            for (int i = 0; i < parent.getChildCount(); i++) {
                View v = parent.getChildAt(i);
                v.setSelected(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
 
Example 12
Source File: LockViewActivity.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
@Override
protected void initView()
{
	grid_number = (GridView) findViewById(R.id.grid_number);

	generateKeyboard();

	mOldPwd = XPreferenceManager.getString(RockyKeyValues.Keys.ENTRY_PASSWORD, "");
	

	pwd_content = (LinearLayout) findViewById(R.id.pwd_content);
	final int pwd_count = pwd_content.getChildCount();
	pwd_items = new EditText[pwd_count];
	for (int i = 0; i < pwd_count; i++)
	{
		pwd_items[i] = (EditText) pwd_content.getChildAt(i);
		if (mMode == LOCK_MODE_DECODE)
		{
			// 解密
			pwd_items[i].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
		}
		else
		{
			pwd_items[i].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
		}

		ViewUtils.hideSoftInput(this, pwd_items[i]);
	}

	pwd_items[0].requestFocus();
	pwd_items[pwd_count - 1].addTextChangedListener(new OnTextInputCompleted());
}
 
Example 13
Source File: ColorPickerView.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public void setColorPreview(LinearLayout colorPreview, Integer selectedColor) {
	if (colorPreview == null)
		return;
	this.colorPreview = colorPreview;
	if (selectedColor == null)
		selectedColor = 0;
	int children = colorPreview.getChildCount();
	if (children == 0 || colorPreview.getVisibility() != View.VISIBLE)
		return;

	for (int i = 0; i < children; i++) {
		View childView = colorPreview.getChildAt(i);
		if (!(childView instanceof LinearLayout))
			continue;
		LinearLayout childLayout = (LinearLayout) childView;
		if (i == selectedColor) {
			childLayout.setBackgroundColor(Color.WHITE);
		}
		ImageView childImage = (ImageView) childLayout.findViewById(R.id.image_preview);
		childImage.setClickable(true);
		childImage.setTag(i);
		childImage.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (v == null)
					return;
				Object tag = v.getTag();
				if (tag == null || !(tag instanceof Integer))
					return;
				setSelectedColor((int) tag);
			}
		});
	}
}
 
Example 14
Source File: MainActivity.java    From BehaviorCollect with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 切换时变色
 *
 * @param index
 */
private void changeTabColor(int index) {
    for (int i = 0; i < mLlMainTab.getChildCount(); i++) {

        LinearLayout currentview = (LinearLayout) mLlMainTab.getChildAt(i);
        ImageView currentImage = (ImageView) currentview.getChildAt(0);
        TextView current_TextView = (TextView) currentview.getChildAt(1);
        switch (i) {
            case 0:
                if (index == i) {
                    currentImage.setImageResource(R.mipmap.ic_tab_home_check);
                } else {
                    currentImage.setImageResource(R.mipmap.ic_tab_home_default);
                }
                break;

            case 1:
                if (index == i) {
                    currentImage.setImageResource(R.mipmap.ic_tab_products_check);
                } else {
                    currentImage.setImageResource(R.mipmap.ic_tab_products_default);
                }
                break;

            case 2:
                if (index == i) {
                    currentImage.setImageResource(R.mipmap.ic_tab_my_check);
                } else {
                    currentImage.setImageResource(R.mipmap.ic_tab_my_default);
                }
                break;
        }

        if (i == index) {
            current_TextView.setTextColor(this.getResources().getColor(R.color.main_tab_text_color_select));
        } else {
            current_TextView.setTextColor(this.getResources().getColor(R.color.main_tab_text_color_unselect));
        }
    }
}
 
Example 15
Source File: PluginManagerTest.java    From crosswalk-cordova-android with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception{
	super.setUp();
	testActivity = this.getActivity();
	containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
	innerContainer = (LinearLayout) containerView.getChildAt(0);
	testView = innerContainer.getChildAt(0);
	
}
 
Example 16
Source File: PluginManagerTest.java    From cordova-amazon-fireos with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    super.setUp();
    testActivity = this.getActivity();
    containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
    innerContainer = (LinearLayout) containerView.getChildAt(0);
    testView = innerContainer.getChildAt(0);
    mWebView = (CordovaWebView) testView;
    pluginMgr = mWebView.pluginManager;

}
 
Example 17
Source File: ActionBarMenuItem.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setPopupItemsSelectorColor(int color) {
    if (popupLayout == null) {
        return;
    }
    final LinearLayout layout = popupLayout.linearLayout;
    for (int a = 0, count = layout.getChildCount(); a < count; a++) {
        final View child = layout.getChildAt(a);
        if (child instanceof ActionBarMenuSubItem) {
            ((ActionBarMenuSubItem) child).setSelectorColor(color);
        }
    }
}
 
Example 18
Source File: ChartProgressBar.java    From ChartProgressBar-Android with Apache License 2.0 4 votes vote down vote up
public void enableBar(int index) {

		final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount();

		for (int i = 0; i < barsCount; i++) {

			FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i);

			int rootChildCount = rootFrame.getChildCount();

			for (int j = 0; j < rootChildCount; j++) {

				if ((int) rootFrame.getTag() != index)
					continue;

				rootFrame.setEnabled(true);
				rootFrame.setClickable(true);

				View childView = rootFrame.getChildAt(j);
				if (childView instanceof LinearLayout) {
					//bar
					LinearLayout barContainerLinear = ((LinearLayout) childView);
					int barContainerCount = barContainerLinear.getChildCount();

					for (int k = 0; k < barContainerCount; k++) {

						View view = barContainerLinear.getChildAt(k);

						if (view instanceof Bar) {

							Bar bar = (Bar) view;

							LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable();
							layerDrawable.mutate();

							ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1);

							GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable();

							if (progressLayer != null) {

								if (mProgressColor > 0)
									progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor));
								else
									progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
							}
						} else {
							TextView titleTxtView = (TextView) view;
							if (mProgressDisableColor > 0)
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor));
							else
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
						}
					}
				}
			}
		}
	}
 
Example 19
Source File: TabLayoutActivity.java    From MaterialDesignDemo with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_layout);
        mTabLayout = (TabLayout) findViewById(R.id.tabLayout);

        // 手动创建Tab
//        for (int i = 0; i < title.length; i++) {
//            TabLayout.Tab tab = mTabLayout.newTab();
//            tab.setText(title[i]);
////            tab.setIcon(R.mipmap.ic_launcher);//icon会显示在文字上面
//            mTabLayout.addTab(tab);
//        }

        // TabLayout与ViewPager结合使用
        mViewPager = (ViewPager) findViewById(R.id.viewPager);
        MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(adapter);
//        // 适配器必须重写getPageTitle()方法
//        mTabLayout.setTabsFromPagerAdapter(adapter);
//        // 监听TabLayout的标签选择,当标签选中时ViewPager切换
//        mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
//        // 监听ViewPager的页面切换,当页面切换时TabLayout的标签跟着切换
//        mViewPager.setOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
        // 关联TabLayout与ViewPager,且适配器必须重写getPageTitle()方法
        mTabLayout.setupWithViewPager(mViewPager);


        mLinearLayout = (LinearLayout) mTabLayout.getChildAt(0);
        // 在所有子控件的中间显示分割线(还可能只显示顶部、尾部和不显示分割线)
        mLinearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        // 设置分割线的距离本身(LinearLayout)的内间距
        mLinearLayout.setDividerPadding(50);
        // 设置分割线的样式
        mLinearLayout.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.divider_vertical));
        mLinearLayout.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));


        // 为TabLayout设置不同状态下的字体大小(并不能成功)
//        for (int i = 0; i < mTabLayout.getTabCount(); i++) {
//            ((TextView) ((LinearLayout) mLinearLayout.getChildAt(i)).getChildAt(1)).setTextSize(10);
////            ((TextView) ((LinearLayout) ((LinearLayout) mTabLayout.getChildAt(0)).getChildAt(i)).getChildAt(0)).setTextSize(12);
//        }
//        ((TextView) ((LinearLayout) mLinearLayout.getChildAt(mTabLayout.getSelectedTabPosition())).getChildAt(1)).setTextSize(30);
//
//        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
//            @Override
//            public void onTabSelected(TabLayout.Tab tab) {
//                ((TextView) ((LinearLayout) mLinearLayout.getChildAt(tab.getPosition())).getChildAt(1)).setTextSize(30);
//            }
//
//            @Override
//            public void onTabUnselected(TabLayout.Tab tab) {
//                ((TextView) ((LinearLayout) mLinearLayout.getChildAt(tab.getPosition())).getChildAt(1)).setTextSize(10);
//            }
//
//            @Override
//            public void onTabReselected(TabLayout.Tab tab) {
//
//            }
//        });


        // 自定义指示器(Indicator)的“长度”的两种方法
        // 方法一:反射
//        setIndicator(mTabLayout,10,10);
        // 方法二:查找子控件
        int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics());
        int right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics());
        for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
            View tabView = mLinearLayout.getChildAt(0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);
            params.leftMargin = left;
            params.rightMargin = right;
            tabView.setLayoutParams(params);
        }
    }
 
Example 20
Source File: PeliasSearchViewTest.java    From open with GNU General Public License v3.0 4 votes vote down vote up
private AutoCompleteTextView getQueryTextView() {
    LinearLayout linearLayout1 = (LinearLayout) peliasSearchView.getChildAt(0);
    LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
    LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
    return (AutoCompleteTextView) linearLayout3.getChildAt(0);
}