Tag: android-layout

How to set android:layout_weight and android:layout_width in code?

Can someone please tell me how to set the android:layout_weight and android:layout_width XML attributes in code for dynamically created views? Reference: XML Table layout? Two EQUAL-width rows filled with equally width buttons?

Navigate among fragments within one activity

I would like to use one Activity which holds several fragments and navigate among the fragments. For example, in the activity, there is a list view which is a fragment, when user select one item from the list, the view will navigate to another fragment, How could this be implemented? I know there is a […]

Android Layout Weight not working with relative layout

Hey Guys Myself Trying to implement layout weight for the first time,a bit i tried with linear layout it works good,but when i tried with relative and linear layout something went wrong.Could you guys suggest me what is wrong here My XML File <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:id=”@+id/Linearlayout” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:orientation=”vertical” android:weightSum=”100″ > <RelativeLayout […]

Override the include's background attribute to change background color

Android Studio 1.5 I have this layout called chat_profile_header that will be used in many layouts. I have set the background to a indigo color. The problem is when I include this header in other layouts, I want to be able to change the background color based on that layout’s theme. Everything in the header […]

I want to set popup width at run time according to title size in android

i tried many things but didn’t get any solution, i m setting text at runtime and i need the width of popup according to text size LinearLayout viewGroup = (LinearLayout) ((Activity) context) .findViewById(R.id.popup); LayoutInflater layoutInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup); title_tv = (TextView) layout.findViewById(R.id.popup_txt); title_tv.setText(title_P); PopupWindow popup = new PopupWindow(context); final […]

Android EditText next focus

I have a couple of EditTexts spread in 2 fragments. One of the fragments has the following xml layout: <?xml version=”1.0″ encoding=”utf-8″?> <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” android:orientation=”vertical” android:paddingBottom=”@dimen/activity_vertical_margin” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” > <TextView android:id=”@+id/title” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:background=”@drawable/cool_button” android:gravity=”center” android:text=”@string/user_account” android:textAppearance=”?android:attr/textAppearanceMediumInverse” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@color/yellow” android:gravity=”center” android:padding=”10dp” android:text=”@string/registration_description1″ android:textAppearance=”?android:attr/textAppearanceSmall” /> <LinearLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:orientation=”vertical” […]

Android custom theme: different theme for landscape and portrait mode

I apply a custom theme to my activity with: <activity android:theme=”@style/MyTheme”>, in which I define the size of the ActionBarSherlock I use in this activity. Something like that: <style name=”MyTheme” parent=”@style/Theme.Sherlock.Light.DarkActionBar”> <item name=”actionBarSize”>45dp</item> <item name=”android:actionBarSize”>45dp</item> </style> While this size is good for portrait mode, I find it too big in landscape mode. How can I […]

How to get “?android:attr/actionBarSize” with Compatibility Library

I’m trying to use Fragments and ActionBar in a Android 2.2 project. There is some error when using “?android:attr/actionBarSize”, how to get and set that value correctly? Example: <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”horizontal” android:layout_width=”match_parent” android:layout_height=”match_parent” android:id=”@+id/frags”> <fragment class=”com.example.android.hcgallery.TitlesFragment” android:id=”@+id/frag_title” android:visibility=”gone” android:layout_marginTop=”?android:attr/actionBarSize” android:layout_width=”@dimen/titles_size” android:layout_height=”match_parent” /> <fragment class=”com.example.android.hcgallery.ContentFragment” android:id=”@+id/frag_content” android:layout_width=”match_parent” android:layout_height=”match_parent” /> </LinearLayout> Error: No resource found that matches […]

Creating shortcuts in Android via Intent

Possible Duplicate: Android create shortcuts on the home screen I am having one TextView and Button in my Activity (HomeActivity.class). Goal: When I click on the Button it should create a shortcut with the default android image as icon and text as entered in the TextView. So far I’ve found out that we can create […]

How to inflate Android View in LinearLayout class?

I’ve got a little piece of xml, which I’ll be using in a lot of places in my app. For this reason I want to store it in a separate file. So I created mywidget.xml in which I have my xml. I then try to inflate this in mywidget.java, after which I want to include […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.