screenshot
Notice that little tiny gray line that runs underneath the tabs (Except selected tab)? How do I change/alter that?
Would that be part of the FrameLayout, tabHost or TabWidget? I just cannot find a way to alter or remove this little gray line.
Thanks
Here is a much simpler way to remove that gray line. Add this to the TabWidget in your layout:
android:tabStripEnabled="false"
Create tabindicator.xml as following.
Then insert following code in to your TabActivity class.
...
View indicator1 = getLayoutInflater().inflate(R.layout.tabindicator,
null);
im1 = (ImageView) indicator1.findViewById(R.id.icon);
im1.setBackgroundDrawable(getResources().getDrawable(
R.drawable.home));
View indicator2 = getLayoutInflater().inflate(R.layout.tabindicator,
null);
im2 = (ImageView) indicator2.findViewById(R.id.icon);
im2.setBackgroundDrawable(getResources().getDrawable(
R.drawable.account));
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator(
indicator1).setContent(new Intent(this, Home.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator(
indicator2)
.setContent(new Intent(this, Accounts.class)))
In here you can change tabindicator.xml according to your requirement.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
I had the same problem. I searched on Stackoverflow and Google many times but there were no answers. Now I solved it. This is how:
tabWidget.setRightStripDrawable(R.drawable.tab_strip);
tabWidget.setLeftStripDrawable(R.drawable.tab_strip);
tab_strip is png image (width:50px,height:2px)
This is tabindicator.xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<RelativeLayout/>
Related
It is showing the image in the Android Studio preview but doesn't show anything when I'm running this on my device. Any ideas why this happens? What's wrong with my code?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myimage" />
</RelativeLayout>
Does your class extend Activity? Try extending AppCompatActivity. I had the same issue and this solution fixed it.
In addition to my comment i've added a few possible soultions. It is very strange the image isn't showing already. Does it show in the imageview in the xml gui design view?
Anyway here are two possible solutions:
xml:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/myimage" />
Also your imageview hasn't been assigned an Id which seems weird something like this would be needed for my second idea:
<ImageView
android:id="#+id/Image_ID"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Java side:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //what ever the name of the activity you are using
Image= (ImageView)findViewById(Image_ID);
Image.setImageResource(Image_ID);
}
Lets hope this helps!
EDIT
<ImageView
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/myimage" />
Note fitXY may lower the quality of the image. try messing with the other scale types
i'm making an android application, and i have a tabhost and two tabs in my xml. I have called them and they work just fine. But i want to get rid of the ugly grey/orange color on tabs. I have tried setting the bg using an image. I used this code:
th.getTabWidget().setBackgroundResource(R.drawable.tab_normal);
But it shows up like this:
How can i get it to replace the gray and orange color?
Thanks
Steps to fully customize tabwidget:
Create custom layout for tabwidget: this layout similar to default one which consist of one Icon and one TextView. You can choose whatever layout you want. Notice that the parent layout has stateful background tabwidget_selector. This drawable is the key to replace default orange focus color. You can choose your own focus color.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#drawable/tabwidget_selector"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/tabIndicatorIcon"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginTop="2dp" />
<TextView
android:id="#+id/tabIndicatorText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:textColor="#color/white" />
Write function which return a view for tabwidget. Set text, icon drawable for your tabwidget
private View getTabIndicatorView(Context context, String tag, int drawable) {
View view = LayoutInflater.from(context).inflate(
R.layout.tab_widget_custom, null);
TextView tv = (TextView) view.findViewById(R.id.tabIndicatorText);
tv.setText(tag);
ImageView tabIndicatorIcon = (ImageView) view
.findViewById(R.id.tabIndicatorIcon);
tabIndicatorIcon.setBackgroundResource(drawable);
return view;
}
Use this function in your activity:
TabHost.TabSpec setIndicator(View view) Specify a view as the tab
indicator.
Intent intent;
TabHost.TabSpec spec;
spec = tabHost.newTabSpec("Inbox").setIndicator(
getTabIndicatorView(MainTabActivity.this, "Hộp thư",
R.drawable.tin_nhan_tab_selector));
intent = new Intent(this, xxxx.InboxActivity.class);
spec.setContent(intent);
tabHost.addTab(spec);
You can have background for tabwidget:
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/tabbackground"
android:layout_margin="7dp"
/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#android:id/tabs"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:background="#drawable/list_shape">
</FrameLayout>
</RelativeLayout>
I want to change the color of the title bar dynamically, ie: someone clicks a button, it changes the color. However, I can't seem to get it to fill the entire title bar. This occurs on both the emulator and a Nexus One. Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/title_bar" android:background="#color/title_bar_blue" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:id="#+id/title_left_text" android:layout_alignParentLeft="true" style="?android:attr/windowTitleStyle" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="#+id/title_right_text" android:layout_alignParentRight="true" style="?android:attr/windowTitleStyle" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</RelativeLayout>
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
titleBar = (RelativeLayout) findViewById(R.id.title_bar);
titleBar.setBackgroundResource(R.color.title_bar_green);
Try this ((View) titleBar.getParent()).setBackgroundColor(R.color.title_bar_green);
It is not the best way to do the job. But if it works, then you will know that you need to set background color of R.id.title_bar parent.
try this
titleBar = (RelativeLayout) findViewById(R.id.title_bar);
final FrameLayout titleContainer = (FrameLayout)titleBar.getParent();
titleContainer.setPadding(0, 0, 0, 0)
titleBar.setBackgroundResource(R.color.title_bar_green);
My class extends a ListActivity, I would like to have a title bar just as "Sound settings" in the following image;
What would be the proper way to create such title.
Thank you for your time.
Creating custom layout can solve this problem.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:orientation="vertical"
<TextView android:id="#+id/textViewCategoriesTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/categoriesTitle"
android:background="#123"
android:layout_gravity="center_horizontal"
android:textSize="30sp" />
<ListView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/listViewCategories"
android:layout_gravity="center_vertical|center_horizontal" />
</LinearLayout>
Hope this can help.
You could add a header view to the list view :
getListView().addHeaderView(myTitleView);
I'm not sure how you can be sure to get the exact same look, though. I would try with just a basic layout containing a TextView and see how that works out.
I want to delete the title bar from my app, but when use the following code, the title bar isn't hidden, in fact it becomes transparent and the content is pushed downwards:
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
So, I have a gap where the title bar used to be (between the notification bar and the app).
I have searched everywhere but haven't found something similar.
Edit:
I have tried both of the solutions given by seretum and harism (shown below) but I'm still unable to find the problem, this is a part of my xml code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff">
<ImageView android:id="#+id/title"
android:src="#drawable/main"
android:layout_width="480dp"
android:layout_height="155dp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"/>
Somehow, the ImageView isn't aligned to the Top of the relative layout...
Last Edit. SOLUTION:
So, I tinkered with the xml and found out that when you set a custom dimension to a widget and so use the Realtuve Layout; no matter if the Title bar is present or not, the Widget will always be under it. So, here is the solution (you need to put the object in a layout):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff">
<LinearLayout android:id="#+id/title"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:maxHeight="155dp"
android:maxWidth="480dp"
android:layout_height="wrap_content">
<ImageView android:src="#drawable/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"/>
Have you tried requesting no title in different order;
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Works for me.
In your app's AndroidManifest.xml, inside the "application" tag, put
android:theme="#android:style/Theme.NoTitleBar"
That will remove your bar from every activity.