Add multiple custom views to layout programmatically

You can inflate the layout2.xml file, edit the texts, and add it to the first layout: public class MyActivity extends Activity { private ViewGroup mLinearLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout1); mLinearLayout = (ViewGroup) findViewById(R.id.linear_layout); addLayout(“This is text 1”, “This is first button”, “This is second Button”); } private void addLayout(String textViewText, String … Read more

Android: Jetpack Compose and XML in Activity

If you want to use a Compose in your XML file, you can add this to your layout file: <androidx.compose.ui.platform.ComposeView android:id=”@+id/my_composable” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> and then, set the content: findViewById<ComposeView>(R.id.my_composable).setContent { MaterialTheme { Surface { Text(text = “Hello!”) } } } If you want the opposite, i.e. to use an XML file in your compose, … Read more

Cannot remove Padding from Tabs when using Custom views with Tab Layout

<android.support.design.widget.TabLayout android:id=”@+id/tab_layout” android:layout_width=”210dp” android:layout_height=”28dp” android:layout_centerInParent=”true” android:background=”@drawable/bg_forum_tab” app:tabIndicatorColor=”@color/colorBtnBg” app:tabIndicatorHeight=”0dp” app:tabPaddingBottom=”-1dp” app:tabPaddingEnd=”-1dp” app:tabPaddingStart=”-1dp” app:tabPaddingTop=”-1dp” app:tabSelectedTextColor=”@color/colorBtnBg” app:tabTextColor=”@color/colorWhite” /> Set tabPaddingStart/tabPaddingEnd/tabPaddingTop/tabPaddingBottom like this.

Android: Multiple view children for custom view with existing layout

It’s absolutely possible, and encouraged, to create custom container views. This is what Android would call a compound control. So: public class MyCustomView extends RelativeLayout { private LinearLayout mContentView; public MyCustomView(Context context) { this(context, null); } public MyCustomView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public MyCustomView(Context context, AttributeSet attrs, int defStyle) { super(context, … Read more

How to get an enum which is created in attrs.xml in code

There does not seem to be an automated way to get a Java enum from an attribute enum – in Java you can get the numeric value you specified – the string is for use in XML files (as you show). You could do this in your view constructor: TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.IconView, … Read more

When drawing outside the view clip bounds with Android: how do I prevent underling views from drawing on top of my custom view?

I found the solution myself, even if this is not optimal for performances. Just add: android:clipChildren=”false” to the RelativeLayout (or whatever layout you have). This has 2 effects (may be more, this are the two that interested me): – the ViewGroup doesn’t clip the drawing of his children (obvious) – the ViewGroup doesn’t check for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)