hey guys i want help in setting my current activity title in my custom actionbar.
my on create function:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.actionbar_custom_view_home);
actionBar.setDisplayShowTitleEnabled(false);
//i guess the line below is wrong
actionBar.setTitle(this.getTitle());
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
}
actionbar_custom_view_home.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" >
<ImageView
android:id="#+id/imageIcon"
android:onClick="Click"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/logo" />
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:textSize="25sp"
/>
</LinearLayout>
Related
I read a half-dozen of threads(particularly this one, who share the issue) about actionBar height, but it seems to no one already get this issue :
My actionBar has an unmodifiable blank(bg color) area under itself :
The custom action bar is defined like this :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityValveassemblyBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
mContentView = binding.fullscreenContent;
mContentView.getWindowInsetsController().setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
mContentView.getWindowInsetsController().hide(WindowInsets.Type.navigationBars()); // HIDE ANDROID UI
// ACTIONBAR
ActionBar actionBar = getSupportActionBar(); // define actionBar
assert actionBar != null;
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); // allow custom
actionBar.setCustomView(R.layout.actionbar_layout); // define custom
As screen said,
<item name="actionBarSize">48dp</item>
<item name="android:windowActionBarOverlay">true</item>
is defined. windowActionBarOverlay = false is the same result.
I can't find what is this area's name, or how to delete it. I can't use these 8 pixels, and until now I only had white bg activites, but I have to use grey background and this line is bothering me so hard.
Edit : and, according to the Layout inspector, this area is... nothing.
Edit2 : with default actionBar and Empty activity :
Edit3 : Add customAction bar layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="38dp"
android:orientation="horizontal"
android:id="#+id/actionbarlinearlayout">
<ImageButton
android:id="#+id/TopLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="#string/settings"
android:src="#drawable/ic_back"
android:background="#00000000"
android:onClick="topLeftButton"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="50dp"
android:contentDescription="#string/shift"
android:src="#drawable/ic_shift" />
<TextView
android:id="#+id/Shift"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginStart="70dp"
android:layout_marginTop="-17dp"
android:fontFamily="#font/fontnats"
android:text="#string/Morningshift"
android:textColor="#color/black"
android:textSize="30sp"
/>
<ImageButton
android:id="#+id/ShiftReload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="172dp"
android:background="#00FFFFFF"
android:onClick="shiftReload"
android:padding="5.5dp"
android:src="#drawable/ic_reload" />
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="10dp"
android:layout_gravity="center"
android:contentDescription="#string/app_name"
android:src="#drawable/ic_logo_bic" />
I put the photo of the account in the navigation header. The border is rectangular, I would like to make it rounded, how can I do that?
In this code I used Glide to display the image.
my_header_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<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="140dp"
android:background="#color/common_google_signin_btn_text_dark_focused"
android:id="#+id/navigation_header">
<ImageView
android:id="#+id/photoImageView"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="18dp"
android:background="#color/colorAccent"
android:visibility="invisible" />
</RelativeLayout>
and in the Main Activity:
private ImageView photoImageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
View hView = navigationView.getHeaderView(0);
photoImageView = hView.findViewById(R.id.photoImageView);
if(user != null){
Glide.with(List.this).load(user.getPhotoUrl()).into(photoImageView);
photoImageView.setVisibility(View.VISIBLE);
}
else{
photoImageView.setVisibility(View.INVISIBLE);
}
Your code i'ts right, you need implement CircleImageView, I show you how to implement.
CircleImageView - GitHub
nav_header_main.xml
<LinearLayout 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="#dimen/nav_header_height"
android:background="#drawable/side_nav_bar"
android:gravity="bottom"
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"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/profile_image"
android:layout_width="150dp"
android:layout_height="150dp"
android:src="#drawable/profile_image"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="0dp"
app:civ_border_color="#EEEEEE"
app:civ_border_width="4dp"
app:civ_shadow="true"
app:civ_shadow_radius="10"
app:civ_shadow_color="#8BC34A"/>
</LinearLayout>
MainActivity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CircleImageView circleImageView = (CircleImageView) findViewById(R.id.profile_image);
Glide.with(List.this).load(user.getPhotoUrl()).into(circleImageView);
}
My NavigationDrawer with CircleImageView
Link Image
NOTE
Remember, your image need proportional dimensioned, example (100x100, 200x200), like a perfect square, I hope I have help you.
I want to add collapsing toolbar in my app. I want to add a graph layout also image view and text views inside the collapsing toolbar layout. Like this image.
This graph is in collapsing toolbar layout. When we do scroll up graph goes up and remains as a toolbar.
Now I am trying to add views under collapsing toolbar layout. But I am not able to move them and align them. How to do?
Layout:
<android.support.design.widget.CoordinatorLayout 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"
android:id="#+id/parentPanel"
xmlns:fab="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="#+id/appbar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_reorder_black_48dp"
android:id="#+id/navigationMenu" />
</android.support.v7.widget.Toolbar>
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_check_box_white_24dp"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp">
<include layout="#layout/card_layout" />
<include layout="#layout/card_layout" />
<include layout="#layout/card_layout" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|right|end"
style="#style/FabStyle"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchor = "#id/parentPanel"
app:layout_anchorGravity = "bottom|right|end"
android:padding="20dp"
android:weightSum="1">
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu1"
android:layout_width="match_parent"
android:layout_height="219dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
fab:menu_labels_ellipsize="end"
fab:menu_labels_singleLine="true"
fab:menu_backgroundColor="#ccffffff"
fab:menu_fab_label="Menu label"
android:layout_gravity="bottom">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add_white_24dp"
fab:fab_size="mini"
fab:fab_label="addList" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="list1" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="list2" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/fab4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_list_white_24dp"
fab:fab_size="mini"
fab:fab_label="list3" />
</com.github.clans.fab.FloatingActionMenu>
</LinearLayout>
Activity:
public class MainActivity extends AppCompatActivity {
private CollapsingToolbarLayout collapsingToolbarLayout = null;
private FloatingActionButton fab1;
private FloatingActionButton fab2;
private FloatingActionButton fab3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final FloatingActionMenu menu1 = (FloatingActionMenu) findViewById(R.id.menu1);
collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle("List Title");
ImageView navigationMenu = (ImageView)findViewById(R.id.navigationMenu);
fab1 = (FloatingActionButton) findViewById(R.id.fab1);
fab2 = (FloatingActionButton) findViewById(R.id.fab2);
fab3 = (FloatingActionButton) findViewById(R.id.fab3);
fab1.setOnClickListener(clickListener);
fab2.setOnClickListener(clickListener);
fab3.setOnClickListener(clickListener);
navigationMenu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,NavigationMenuActivity.class));
overridePendingTransition(R.anim.left, R.anim.enter);
}
});
menu1.setOnMenuButtonClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (menu1.isOpened()) {
Toast.makeText(MainActivity.this, menu1.getMenuButtonLabelText(), Toast.LENGTH_SHORT).show();
}
menu1.toggle(true);
}
});
menu1.setClosedOnTouchOutside(true);
dynamicToolbarColor();
toolbarTextAppernce();
}
private void dynamicToolbarColor() {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.b);
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
#Override
public void onGenerated(Palette palette) {
collapsingToolbarLayout.setContentScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimary)));
collapsingToolbarLayout.setStatusBarScrimColor(palette.getMutedColor(getResources().getColor(R.color.colorPrimaryDark)));
}
});
}
private void toolbarTextAppernce() {
collapsingToolbarLayout.setCollapsedTitleTextAppearance(R.style.collapsedappbar);
collapsingToolbarLayout.setExpandedTitleTextAppearance(R.style.expandedappbar);
}
private View.OnClickListener clickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
String text = "";
switch (v.getId()) {
case R.id.fab1:
text = fab1.getLabelText();
break;
case R.id.fab2:
text = fab2.getLabelText();
fab2.setVisibility(View.GONE);
break;
case R.id.fab3:
text = fab3.getLabelText();
fab2.setVisibility(View.VISIBLE);
break;
}
}
};
}
Now I have a single image view inside collapsing toolbar layout and that I can't move or align. How to align view and add views under collapsing toolbar?
Thank you..
CollapsingToolbarLayout is a subclass of FrameLayout.
For maximum flexibility, put all your widgets inside a LinearLayout or RelativeLayout and make it the only child of the CollapsingToolbarLayout. Also for best results with vertical sizing, set the height to a specific dimension.
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/graph_toolbar_height"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseMode="parallax">
<!-- graph UI here -->
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
Create a layout inside collapsingtoolbarlayout and add your views in there.
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#color/colorPrimary"
app:expandedTitleGravity="bottom|center_horizontal"
app:expandedTitleMarginBottom="64dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="230dp"
android:scaleType="centerCrop"
android:src="#drawable/ic_about"
app:layout_collapseMode="parallax" />
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/colorAccent"
android:text="#string/about_title"
android:textSize="#dimen/text_size_large" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_marginTop="#dimen/status_bar_height"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
I have the following code:
public class MainActivity extends ActionBarActivity {
EditText userfield;
EditText passfield;
Button logbtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userfield = (EditText)findViewById(R.id.editText);
passfield = (EditText)findViewById(R.id.editText2);
logbtn = (Button)findViewById(R.id.button);
GifWebView view = new GifWebView(this, "file:///android_asset/watg.gif");
view.getSettings().setLoadWithOverviewMode(true);
view.getSettings().setUseWideViewPort(true);
setContentView(view);
userfield.bringToFront();
userfield.invalidate();
passfield.bringToFront();
passfield.invalidate();
logbtn.bringToFront();
logbtn.invalidate();
}
As you can see the GifWebView (extends WebView) is created programatically after the onCreate()
The button and EditTexts are made in the Activity.xml but are brought to front programatically in the Java file.
Why doesnt the above code work?
EDIT - Frame Layout Problem
My XML Code
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.example.dencallanan.giftestapp.GifWebView android:id="#+id/GWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<RelativeLayout 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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_marginBottom="153dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="USERNAME" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_marginTop="58dp"
android:layout_alignTop="#+id/editText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/editText"
android:layout_alignStart="#+id/editText"
android:hint="PASSWORD" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log In"
android:id="#+id/button"
android:layout_below="#+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
</RelativeLayout>
</FrameLayout>
The Error:
You are calling setContentView(R.layout.activity_main) and again later setContentView(view). setContentView will overwrite the layout, this will in effect, replace it with a new layout. I suggest using a FrameLayout in XML file... Webview will be your bottom layer. On top of that Put a Linear/RelativeLayout with the Edittexts and Button... Simple and clean.
You can add your webview in XML like:
<com.package.GifWebView android:id="#+id/GWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
In code, access this as:
GifWebView gWView = (GifWebView) findViewById(R.id.GWebView);
gWView = new GifWebView(this, "file:///android_asset/watg.gif");
I want to center an image on my action bar. So here it goes...
Here's my actionbar_about.xml file. In this xml file is the image located
<?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"
android:orientation="horizontal" >
<ImageView
android:id="#+id/about_actionbar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:src="#drawable/ic_about" />
</RelativeLayout>
And this is where I will overlay or inflate that xml file.
AboutUs.java. This ain't mainactivity.java that's why I'm using getActivity()
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ActionBar
ActionBar mActionBar = getActivity().getActionBar();
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(getActivity());
View mCustomView = mInflater.inflate(R.layout.actionbar_about, null);
ImageView mImageView = (ImageView) mCustomView.findViewById(R.id.about_actionbar);
mImageView.setImageDrawable(getResources().getDrawable(R.drawable.ic_about));
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
}
THANKS GUYS! :)
you can try this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent" android:textAppearance="#style/TextAppearanceRegular.FontPath"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/gridItemImg"
android:contentDescription="#string/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:clickable="true"
android:layout_alignParentTop="true"
android:src="#drawable/box" android:padding="1.5dip"
android:layout_centerHorizontal="true"
android:background="#drawable/item_selector" />
<TextView
android:id="#+id/gridItemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/gridItemImg"
android:layout_centerHorizontal="true"
android:ellipsize="end"
android:singleLine="true" android:layout_marginTop="10dp"
android:text="#string/title"
android:textColor="#ffffff"
android:textSize="12sp" />