Getting rid of unmodifiable blank area under actionBar? - java

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" />

Related

Android not animating the Relative Layout

I am creating a Relative layout which I want should come from above sliding into the layout so here's what I did
made the layout invisible
In oncreate animated the layout above the screen
and in onWindowsFocusChanged() I called animation , made layout visible and want layout to slide into the screen
BUT
when view is created the layout is at its right location with out showing any sliding effect from coming from top of screen
public class OverlayActivity extends Activity implements View.OnClickListener {
RelativeLayout question_box;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_overlay);
// Slide Up the INVISIBLE layout so that I can call it by animation back to its original position
question_box = findViewById(R.id.question_box);
question_box.animate().translationY(-question_box.getHeight());
final Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
public void animateInObjects() {
question_box.setVisibility(View.VISIBLE);
question_box.animate().setDuration(1000).translationY(0);
}
#Override
public void onClick(View v) {
//Some Code
}
#Override
protected void onStop() {
super.onStop();
finish();
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
animateInObjects();
super.onWindowFocusChanged(hasFocus);
}
}
Layout
<RelativeLayout
android:id="#+id/question_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:layout_marginTop="5dp"
android:layout_below="#+id/ad_view_container"
android:visibility="invisible">
<TextView
android:id="#+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/questiontext"
android:paddingStart="20dp"
android:paddingTop="7dp"
android:paddingEnd="20dp"
android:paddingBottom="20dp"
android:text="#string/sample_question"
android:textAlignment="center"
android:textColor="#color/text_quest"
android:textSize="23sp" />
<View
android:id="#+id/center_vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerVertical="true" />
<LinearLayout
android:id="#+id/cover_opt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/question"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:background="#drawable/main_layout">
<Button
android:id="#+id/opt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="1dp"
android:layout_marginHorizontal="2dp"
android:background="#android:color/transparent"
android:text="#string/sample_number"
android:textAlignment="center"
android:textColor="#color/text_quest"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/cover_opt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/question"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#drawable/main_layout">
<Button
android:id="#+id/opt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="1dp"
android:layout_marginHorizontal="2dp"
android:background="#android:color/transparent"
android:text="#string/sample_number"
android:textAlignment="center"
android:textColor="#color/text_quest"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/cover_opt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/question"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
android:background="#drawable/main_layout">
<Button
android:id="#+id/opt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="1dp"
android:layout_marginHorizontal="2dp"
android:background="#android:color/transparent"
android:text="#string/sample_number"
android:textAlignment="center"
android:textColor="#color/text_quest"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>
this is the theme of the activity
<style name="Theme.Lockscreen" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">#33000000</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
well you try to animate the view in onCreate method. at first the view is not drawn yet and you get a getHeight = 0 .so you must wait when the view is drawn by using view.getViewTreeObserver().addOnGlobalLayoutListener to be able to animate it
you need to add this on your onCreate() :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
// Slide Up the INVISIBLE layout so that I can call it by animation back to its original position
question_box = findViewById(R.id.question_box);
question_box.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
if (question_box.getHeight() != 0)
question_box.animate().translationY(-question_box.getHeight());
}
});
final Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
Try this as your xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromYScale="0"
android:toYScale="50%"
android:duration="1000"></scale>
</set>
To have it till half of your screen and arrange layout respectively

Android custom fonts Lollipop

I have two TextView which I want to put a custom font on.
In the OnCreate of my MainActivity, after the setContentView call, I wrote the following code:
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/BernerBasisschrift1.ttf");
TextView welcomeTextView = (TextView)findViewById(R.id.welcome_message);
TextView introTextView = (TextView)findViewById(R.id.introduction_message);
welcomeTextView.setTypeface(myTypeface);
introTextView.setTypeface(myTypeface);
But for some reason, the font stays default.
The app runs on Galaxy S6 Edge device (Lollipop 5.0.2).
I read here that there's a problem with custom fonts on Lollipop, and in order to fix it I converted my font with the tool provided in the thread to ttx and vice versa, but even this didn't help.
Any ideas what can I do?
Edit:
Tested on Jellybean (4.3), not working either.
Another edit:
It works on a clean new project! Cant figure out the difference.
Putting the MainActivity and its' XML for help:
public class MainActivity extends FragmentActivity {
private LoginFragment loginFragment;
private TextView welcomeTextView;
private TextView introTextView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideActionBar();
setContentView(R.layout.activity_main);
welcomeTextView = (TextView)findViewById(R.id.welcome_message);
introTextView = (TextView)findViewById(R.id.introduction_message);
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "fonts/BernerBasisschrift1.ttf");
welcomeTextView.setTypeface(myTypeface);
introTextView.setTypeface(myTypeface);
if (savedInstanceState == null) {
// Add the fragment on initial activity setup
loginFragment = new LoginFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, loginFragment, "facebookFragment").commit();
}
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
if(hasFocus){
// get all views on screen
ArrayList<View> views = new ArrayList<View>()
{{
add(findViewById(R.id.welcome_message));
add(findViewById(R.id.introduction_message));
add(findViewById(R.id.below_login));
add(findViewById(R.id.above_login));
add(findViewById(R.id.authButton));
add(findViewById(R.id.logo));
}};
// set animations
for(View view : views)
YoYo.with(Techniques.Tada).duration(700).playOn(view);
}
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void hideActionBar(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
getActionBar().hide();
}
And the activity's XML:
<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:background="#drawable/main_background">
<ImageView
android:id="#+id/logo"
android:layout_width="256dp"
android:layout_height="101dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:background="#drawable/logo" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp">
<TextView
android:id="#+id/welcome_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/welcome_message"
android:textColor="#color/White"
android:textSize="25sp"
style="#style/ShadowStyleText"
android:gravity="center" />
<TextView
android:id="#+id/introduction_message"
android:layout_below="#+id/welcome_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/introduction_message"
android:textColor="#color/White"
android:textSize="18sp"
android:gravity="center"
style="#style/ShadowStyleText"
android:layout_marginTop="5dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/bottom_login_chunk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginEnd="50dp"
android:layout_marginRight="50dp">
<TextView
android:id="#+id/above_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/above_login_button"
android:textColor="#color/White"
android:textSize="18sp"
style="#style/ShadowStyleText"
android:gravity="center" />
<com.facebook.widget.LoginButton
android:id="#+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/above_login"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp" />
<TextView
android:id="#+id/below_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/authButton"
android:layout_centerHorizontal="true"
android:text="#string/below_login_button"
android:textColor="#color/White"
style="#style/ShadowStyleText"
android:textSize="14sp" />
</RelativeLayout>
</RelativeLayout>
Ok so I found out recently that the facebook login button caused the problem, since everything worked when it was commented out.
So basically to solve this problem use another method to show the button instead using support fragment manager; sdk docs has lots of examples.

text view on the image view?

the text should be saved on the image view ?the text should not be defined in the layout folder and should be saved on the image view on the accordingly from the key board ?
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullimage);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.fullimage);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
}
}
use framelayout for that .. define both ImageView and TextView and set text on TextView
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/thumbHolder">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/thumbImage"
android:scaleType="fitXY" />
<TextView
android:layout_width="match_parent"
android:layout_height="24dp"
android:id="#+id/titletxt"
android:gravity="center_vertical"
android:maxLines="2"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:textSize="16sp"
android:layout_gravity="bottom"
android:background="#80000000"
android:textColor="#ffffffff"
android:text="" />
</FrameLayout>
for setting custom font :-
create "assets\fonsts\" folder and then place your font there
then create a typeface by loading that font :-
Typeface tfBold = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Raleway-Bold.otf");
then set your typeface in textView :-
yourTextView.setTypeface(tfBold);
try this-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#drawable/image">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
android:singleLine="true"
android:text="text"/>
</LinearLayout>
</LinearLayout>
You can either draw the image on a canvas, and then draw the text on the image or else, create a layout via code and set the textview inside the layout and then place the layout on top of the image view with background of the textview set to transparent
You can do it using TextView only. Using drawableTop, drawableBottom, drawableLeft, drawableRight in the following way.
<TextView
style="#style/layout_wrap"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingRight="5dp"
android:drawableTop="#drawable/flags_00"
android:textColor="#color/text_color_tabs"
android:textStyle="bold"
android:maxLength="3"
android:gravity="center"
android:text="Team B" />
and in the code by the following way
battingTeamFlag.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
You can use Button and use button background to set image.and use text element for adding text on button.
<Button
android:layout_width="wrap_parent"
android:layout_height="wrap_parent"
android:text="YourText"
android:background="#drawable/image"
>
</Button>
According to your requirement you can get text from button and pass it with intent

How to enable batch contextual actions in a ListView?

I'm trying to follow the official Android guide for CABforListView very closely, but I have not been able to activate context action view on my ListView item long press.
public class MainActivity extends ListActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadList(); // loads Cursor data and sets list adapter in AsyncTask
ListView listView = getListView();
listView.setLongClickable(true); // no effect
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
// implemention of MultiChoiceModeListener
});
}
// rest of the class
}
The following is my list_row_item.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?android:attr/activatedBackgroundIndicator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:longClickable="true"
android:paddingLeft="15dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp" >
<TextView
android:id="#+id/reminder_row_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/reminder_row_interval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/reminder_row_description"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Switch
android:id="#+id/switch_reminder_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/reminder_row_interval"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/reminder_row_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/reminder_row_interval"
android:layout_below="#+id/reminder_row_interval"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
And my activity_main.xml:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
I have tried using listView.setOnItemLongClickListener() to start ActionMode manually, but while that has launched contextual action mode I was not able to do multiple selects, and no tutorial/guide has ever needed to do this. I am missing something.
Basically, I want to achieve exactly this effect as seen in Jelly Bean's alarm clock:
Any pointers would be greatly appreciated!
Based on #Luksprog comment, returning true from onCreateActionMode() will fix your problem

custom actionbar title in android

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>

Categories

Resources