How to create clickable icons on the Custom Title Bar - android-layout

I want to create the click effect on the following type of custom title Bar.
There are three functions in here:Home,Title and Search, clicking either of it should perform the further function.
I was following this
http://staticallytyped.wordpress.com/2011/03/18/android-dynamic-and-custom-title-bars/
But i want the effect which i have posted above.

The thing you are talking about is called Action Bar. This is specially designed for Android Tablets. But developers have made Action Bar available for Android Mobile Phones too.
Have a look at Action Bar written by johannilsson. You can simply download this library project and customize according to your need and then integrate this library to your project.
Other Action Bar examples :
Xoriant Action Bar --
Note : THIS IS THE SAME THING THAT YOU WANT as you want to have Home, Search and Title on it.
Thiranjith blogspot

Just try this..
1) First create two layouts like main & custom_title
2) You must include the drawables which type like you've posted here. And, use this code.
main.xml - Just designed whatever you want.
custom_title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="hello"
android:text="Button" />
</LinearLayout>
Main.java
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
}
public void hello(View view)
{
Toast.makeText(getApplicationContext(), "Hi, this is test.", Toast.LENGTH_LONG).show();
}
Change this code to your needs. Hope this helps you.

Related

how to extend ImageView class in kotlin?

I found strange behavior when extending ImageView in kotlin.
I have following layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<AlphaImage
android:id="#+id/imageView2"
android:layout_width="320dp"
android:layout_height="50dp"
app:srcCompat="#drawable/blitz_1st_place" />
</FrameLayout>
AlphaImage class:
class AlphaImage(context: Context,attrs:AttributeSet?=null):ImageView(context,attrs) {
}
The layout preview in android studio shows image as 100% transparent as well as in runtime.There are no errors in the layout editor.What interesting is if I change AlphaImage to ImageView image starts to display its content as expected.Why is this happening?How do I extend ImageView?
The issue here is the app:srcCompat attribute. That is a support/androidx library attribute for the AppCompatImageView class. The framework ImageView will just ignore it.
The reason this works when you use an <ImageView> tag instead is because the support/androidx LayoutInflater that AppCompatActivity uses will automatically substitute an AppCompatImageView for any <ImageView> tag it finds. The AppCompatImageView will then see that app:srcCompat attribute, and handle its value appropriately.
If you'd like your custom class to handle that attribute automatically, simply extend AppCompatImageView instead of ImageView.

Cannot Resolve Symbol R Upon New Project Creation

There seem to be many threads addressing this question, but none have worked for me. My problem is that whenever I start a new project, R is highlighted red, and the project will not run.
Luckily - for the sake of simplicity - I have not implemented any code, all the code in the project is simply the code created by the creation of a new project:
package com.abc.android.unnamed;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
The XML file remains unchanged:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.abc.android.unnamed.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
I have tried:
Deleting the project files and creating a new project
Doing Build > Clean Project, then Build > Rebuild Project
All of which yield the same result.
Each time, the Gradle Console displays:
What can I do to fix this issue?
After some digging, I fixed my problem. My antivirus (Bitdefender) was not giving access to aapt2.exe, as seen in the error from the Gradle Console.
This was not immediately obvious as I did not see any notification that it was blocked. Additionally, sample code was able to resolve R without any fuss, so I was confused why I was not able to get it working. After allowing aapt2.exe access, with a Gradle rebuild, there is no longer an issue.
I'm just gonna add this here as i can't comment yet, for anyone experiencing the same issue.
I think Windows Defender does the same thing. As soon as i shut off the real-time protection the symbol R was resolved.

android app side menu like google map menu

I am looking to put side menu similar to "google map" side menu which appears next to "Search Google Maps" you click on the icon and you get menu
is there any framework to implement ?
spending much time but can't find out how
can any expert advise/suggest/help me
I would appreciate your help very much
What you are looking for is navigation menu with layout_gravity="start".
Declare your layout like as shown below:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer_layout"
tools:context=".MyActivity">
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/navigation_view"
android:layout_gravity="start">
//put your menu items here...
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
If u want to see the hamburger icon as well then use the code below:
actionBarDrawerToggle=new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
drawerLayout.setDrawerListener(actionBarDrawerToggle);
and override onPostCreate as:
#Override
protected void onPostCreate(Bundle savedInstanceState){
super.onPostCreate(savedInstanceState);
actionBarDrawerToggle.syncState();
}
Let me know if this is not enough for you...

Is there any sliding menu with visible column before click?

I've searched but no result.
I would like have menu where you see still column and when you click on it, it will slide right or left showing the rest of layout. What is more it should slide over my activity.
Any help?
I'm looking for something like that:
I found sliding menu from jfeinstein only but when you swipe, your screen is moving also.
Thanks in advance.
This is probably what you need.
Example:
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<shared.ui.actionscontentview.ActionsContentView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:actions_layout="#layout/actions"
app:actions_spacing="50dp"
app:content_layout="#layout/content"
app:shadow_drawable="#drawable/shadow"
app:shadow_width="8dip"
app:spacing="64dip"
app:spacing_type="right_offset" />
</RelativeLayout>
app:actions_layout="#layout/actions" - this is the layout for your left side menu. You can put there everything you want
app:actions_spacing - offset from left side in dp - that means how much the left menu will be visible
app:content_layout="#layout/content" - this is the layout for main content. You can also put there everything. For example there you can have a FrameLayout and you can attach a fragment from code based on what menu item a user clicked
app:spacing_type="right_offset" and app:spacing="64dip" - that means that when left menu is opened, then how much the main content will be visible
MainActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.activity_main);
mSlidingMenu = (ActionsContentView) findViewById(R.id.content);
//this will open menu
mSlidingMenu.showActions();
//this will close menu
mSlidingMenu.showContent();
}

`VideoView.start()` cause other views to break

When my activity receives a new intent via onNewIntent, it updates the data of three Views, an ImageView, a TextView, and a VideoView. The problem is, the two other views just flash, then disappear when my VideoView comes on. After scattering a few breakpoints, I discovered that they appear when their content is set, but disappear when VideoView.onStart() is called in my MediaPlayer.onPrepared() method. I also have an AlertDialog show up when the menu button is pressed. After pressing the menu button, it shows up. I'm on Android API 9, as this is the API on the device I'm working on. I really need help, so I'd appreciate any advice.
Here's the layout. I don't think it's the issue though:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true" >
<TextView
android:id="#+id/marquee"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:ellipsize="marquee"
android:focusable="false"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="#android:style/TextAppearance.Large"
android:textColor="#android:color/white" >
</TextView>
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_above="#id/marquee"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_vertical" />
<VideoView
android:id="#+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/marquee"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toLeftOf="#+id/image" />
</RelativeLayout>
Take note that the TextView is meant to be a marquee; it's supposed to keep scrolling sideways, until it is disposed of. I discovered that when the text is too short for it to start the marquee, the TextView AND the ImageView disappear (as stated earlier, they appear for a split second, then disappear). However, when the text causes the marquee feature to activate, everything works.
CURRENTLY:
I got it to work by calling postInvalidateDelayed(500) on my ImageView and TextView after calling VideoView.start(). I think the start() method is causing the problem, and requires that other views call invalidate(). Also, for some reason, there needs to be a small delay in-between the call to start() and the call to invalidate().
The layout is the issue.
Your VideoView is declared as match_parent, match_parent, allowing it to consume the whole width and height of the screen. Since you declared it last on the xml file (You used RelativeLayout. Ordering matters), the TextView and the ImageView would be covered by the VideoView.
If you're confused,
match_parent is basically the same as fill_parent. It's just another name for fill_parent in android 2.3+
Now what can you do about it?
Reorder your views in such a way that the largest is declared first. In this case, VideoView, then ImageView, then TextView.
Also note that your ImageView has height set to fill_parent - you may not want that.
I created a method, but it seems very bad:
private void startVideo() {
this.videoView.start();
if (this.imageView != null)
this.imageView.postInvalidateDelay(500);
if (this.textView != null)
this.textView.postInvalidateDelay(500);
}
It works, but it makes me feel dirty.

Resources