Custom title with image
i'm creating custom title for activity by disabling standard one and managing everything myself. I wonder if it's possible to replace/theme standart title to my needs.
I can customize size, background image, and text via themes by changing windowXYZStyle items.
The only thing i couldn't find - how i can add image instead of text.
I've tried requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)
and assign custom layout - but it doesn't seems to work.
EDIT : Here is a report of testing suggestions, code is below - result - image view is not showing up.
Activity
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
XML :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:paddingLeft="5dip"
android:background="@drawable/titlebar_bg"
android:layout_gravity="left|center"
>
<ImageView
android:id="@+id/logo"
android:src="@drawable/title_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Asked by: John312 | Posted: 25-01-2022
Answer 1
It's possible to set your own custom title layout, however the order of execution matters. You must do things in this order:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_title);
Additionally, you may need to increase the size of the title; if you don't, then the bottom of your custom layout may just be covered up by your Activity. You can change the size by adding a theme that specifies the title's size. This would go into a values XML file:
<resources>
<style name="LargeTitleTheme">
<item name="android:windowTitleSize">40dip</item>
</style>
</resources>
Then you'd need to set the theme for your Activity (or Application, if you want the entire application to have this custom title bar) in AndroidManifest.xml:
<activity android:name=".MyCustomTitleActivity" android:theme="@style/LargeTitleTheme" />
Answered by: Ada305 | Posted: 26-02-2022
Answer 2
You could always use:
requestWindowFeature(Window.FEATURE_NO_TITLE);
And then create your own title bar inside your Activity's View.
Answered by: John572 | Posted: 26-02-2022Answer 3
Are you sure that you need to use an image in the title rather than just combining it as part of your background image and leaving the title blank? Using a NinePatch image I would expect that you would be able to achieve a result that would look good on regardless of the device?
Answered by: Aldus143 | Posted: 26-02-2022Answer 4
I have used the following code to fit my custom title to the screen
<ImageView
android:id="@+id/header_img"
android:src="@drawable/header_img"
android:layout_width="700dip"
android:layout_height="70dip" />
Answered by: Freddie448 | Posted: 26-02-2022
Similar questions
Android "hover" event in custom layout
I have a custom layout that I have written that basically just displays a bunch of ImageViews. I am handing onTouch events for all the ImageViews in my layout.
However, if a user touches one imageView and then drags over another ImageView, I would like to be able to handle that as well.
How would I go about capturing this behaviour?
android custom view how to draw button on top of the view
I am creating a android app using LunarLander as a example.
Now I need to create a few buttons which are drawn over the view.
I do not want them as a seperate layout above or below the view but in the custom view.
Is this possible or am I going to have to programmatically show the button images then detect the touch. The buttons I create using new never show on the app. I assume this is because I have overwritten the onDra...
android - Input Field With Custom Input Method
I would like to show a custom input field (specifically, one containing only 9-0 and two extra buttons containing decimal separator (, or .) and a delete button).
I could create a custom IME, but (as far as I know) that would have to be set by the user as the system-wide input method. Is there a way to implement an input method and bind it to a specific input field?
Thanks for the help!
How to put Custom View above built in views in Android?
I am developing a small app for Android. I am creating my own view.
I am planning to design the layout to be:
<LinearLayout>
<MyView>
<Button><Button>
</LinearLayout>
But when I run my program, my custom view will cover the whole screen. Is there anyway to avoid this?
I have already tried to add android:layout_width, la...
android - custom view with layout
ok,
what i am trying to do is to embed a custom view in the default layout main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.lam.customview.CustomDisplayView
android:id="@+id/cus...
Android custom xml widget
I have an XML file in my layout folder that has how i want my custom widget/view (not sure what correct terminology is here).
but how do i make it so that i can programatically, add one or more to an activity
the xml file is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="ve...
Android - Custom Widget doesnt update
I'm trying to make a widget to my app, but it doesnt update.
I just need to change the textview text and open an activity when a press a button, but none of them works...
the code:
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.newswidget);
views.setTextViewText(R.id.tvNews,...
android - digital compass problem
I am creating an augmented reality application and I noticed that the stored locations don't appear appear on the correct direction if I try to use the camera view (using layar or wikitude API).
The problem is that the digital compass doesn't show north correctly when you try to look at the known objects through the camera view. If align the phone with the ground (look at my shoes) the locations appear at the screen accord...
android - How to remove labels from a MapView?
I am trying to make a satellite view (via a MapView) without labels. How can I do this?
canvas - Android draw with blur
I need do draw on Android's Canvas using Blur effect,
it is a very simple feature,
I need to draw a circular area, which is blurred (the foreground) and the background transparent, I can do everything with manipulating the colour alpha to do it with custom transparency but I need it to be blurred instead of transparent..
any ideas?
layout - How to resize a android webview after adding data in it
In a layout (linear, vertical) hierarchy I've got several views and one of them is a WebView.
They all have same parameters:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
For all views, the spacing between elements is correctly handled but for the Webview there is a lot of spaces after the displayed text inside.
I set the (HTML) text of the webview in the ...
How to find easily the source of an android class
I know I can access android source code from https://android.googlesource.com, but it's hard to select the right git repo if I only know the package and the name of an android class.
Isn't there a way to locate a file in https://android.googlesource.com?
camera - Android Intent Save Path
At the moment I am using two intents. One for voice-recording, another for the camera:
Intent photoIntent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(photoIntent, ACTIVITY_TAKE_PHOTO);
Intent voiceIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(voiceIntent, ACTIVITY_RECORD_SOUND);
My aim is to put an Extra to each of t...
Android "hover" event in custom layout
I have a custom layout that I have written that basically just displays a bunch of ImageViews. I am handing onTouch events for all the ImageViews in my layout.
However, if a user touches one imageView and then drags over another ImageView, I would like to be able to handle that as well.
How would I go about capturing this behaviour?
android - What is the ideal place to cache images?
I am fetching a lot of thumbnails in my application from a remote server and lazy-loading these in a list view.
The image fetches run in a background AsynTask and when completed the fetched images are stored in a HashMap using SoftReferences.
This works just fine but when the images in the cache gets GC’d, the fetches have to be rerun.
I could have stored them on the SD card so there would be no...
How to create a tree view in Android?
There are no controls in Android that provide Tree-like View. There is an ExpandableList View which I suspect could be used to creating one.
Have you tried imlpementing such a control?
How would one implement such a control in Android?
android how to scroll to see all the widget of the view
In one of my androids activities, I have several widget in a vertical linearlayout. The length of this layout is bigger than the screen and thus I cannot see the widget at the bottom.
In the Emulator, is there a special scroller to implement or a particular action to do to be able to scroll up and down ?
Thanks a lot,
Luc
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android