I am trying to make a alert dialog which will show like the picture.
Im trying to use frame layout but can't make the it right like the picture. In my current layout I used an imageView and textview.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src=""/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#strings/text"
/>
</FrameLayout>
<!---<other layouts--->
</LinearLayout>
Create an Activity it represents your overlay.
Put this in your onCreate
requestWindowFeature(Window.FEATURE_NO_TITLE);
#Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE); //importan no title show
super.onCreate(savedInstanceState);
setContentView(R.layout.overlay);
}
put this in styles.xml
<style name="FloatingPopup" parent="#android:style/Theme.Black.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
</style>
In your manifiest declare the activity thath looks like a overlay and add the theme
<activity
android:name=".YourOverlayActivity"
android:screenOrientation="portrait"
android:theme="#style/FloatingPopup" >
</activity>
It looks like a semitransparent activity and now you can custom with xml layout editor.
A FrameLayout will stack the Views, causing them to overlap each other. If you want one directly above the other, consider using a LinearLayout with the orientation set to vertical.
Update: Try this, replacing your FrameLayout with a LinearLayout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#strings/text"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src=""/>
</LinearLayout>
Obviously fill in the src parameter for the ImageView with your image.
Related
I am trying to make my first hamburger menu with some images, but they are displayed in grey scale, not the real image. Here is a photo of how it looks:
And here is the code for the XML file:
<item
android:id="#+id/desp_mercedes"
android:icon="#drawable/mercedes"
android:title="Mercedes" />
<item
android:id="#+id/desp_audi"
android:icon="#drawable/audi"
android:title="Audi" />
<item
android:id="#+id/desp_bmw"
android:icon="#drawable/bmw"
android:title="BMW" />
I want to know how to display the original images. I have both SVG and PNG files for better quality.
In your nav_header_main.xml layout resource file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/nav_header"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#color/colorAccent"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:gravity="bottom"
android:orientation="vertical"
android:padding="16dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
//here you can add your image src
<ImageView
android:id="#+id/nav_header_imageView"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="#drawable/ic_imageview" />
<TextView
android:id="#+id/nav_header_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:text="Chike Mgbemena"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
</LinearLayout>
You can maybe try this out: How do I customize the navigation drawer in Android Studios?
TL;DR: Create a ListView in your DrawerLayout with the appropriate implementation, Adapter, item.xml and such.
I found the way to display the original images, here is the fragment of code:
navigationView.setItemIconTintList(null);
"navigationView" is the name for my drawer, change it to yours on your MainActivity
I am using actionbar and displaying some title and subtitle of the actionbar. I want the size of subtitle to be smaller than the title. And also I have a logo icon in left. So how should I adjust the alignment.
There's an another fragment in which I am using back button as home button. So, I also want to reduce the space between the back button and the Title of actionbar.
I tried using this code. But it didn't help.
UserListFragment.java
View viewActionBar = getActivity().getLayoutInflater().inflate(R.layout.actionbar_layout, null);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,ActionBar.LayoutParams.MATCH_PARENT,Gravity.CENTER);
TextView textviewTitle = (TextView) viewActionBar.findViewById(R.id.mytext);
textviewTitle.setText("DemoIosAppDoctor"+"\n"+"Doctor");
actionBar.setCustomView(viewActionBar, params);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
actionbar_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:id="#+id/mytext"
android:textSize="18sp"
android:layout_marginTop="5dp"
android:layout_marginLeft="-2dp"/>
</LinearLayout>
To completely customise Actionbar, you should define Toolbar in design XML and add you own component there. and, then use like this
Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(tb);
Use XML like this:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
Note: You have to set this activity theme as NoActionBar like this:
<activity
android:name=".YourActivity"
android:parentActivityName=".index.IndexActivity"
android:theme="#style/AppTheme.NoActionBar" />
And theme like this:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
I am a fresher to Android Design. I Have Android Studio's Navigational DrawerLayout, when my app loads I'm loading Initial Fragment for the app.
I want to make the toolbar transparent
I want to have an image that is overlapping the DrawerLayout's toolbar
and for other Fragments I want the same toolbar to be opaque.
First Screen when app Loads
When any other fragment is called
For No :1.
All you need to is to define theme which hide action bar, define action bar style with transparent background and set this style to the toolbar widget. Please note that toolbar should be drawen as last view (over all view tree)
<style name="Theme.Custom" parent="#android:style/Theme.AppCompat">
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
<style name="CustomActionBar" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar should be above content-->
<include layout="#layout/toolbar" />
</RelativeLayout>
Toolbar layout:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/CustomActionBar"/>
For No : 2
Put ImageView in relative layout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Toolbar should be above content-->
<include layout="#layout/toolbar" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:transitionName="photo_hero"
android:id="#+id/image"
/>
</RelativeLayout>
Toolbar layout:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="#style/CustomActionBar"/>
I am trying to add a button to title bar but I couldn't succeed. I have read many articles about this but they all explain the way that doesn't fit my situation. I am using ScrollView to make the screen scrollable. but articles suggest me to use linear layout. How can I make it scrollable and have a button on the title bar?
here is my XML
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#C0C0C0"
android:id="#+id/sw_layout">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:id="#+id/ln_layout">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft=<"#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
.........................
.........................
.........................
</TableLayout>
</LinearLayout>
</ScrollView>
And in my MainActivity, I have this code....
LinearLayout ln = (LinearLayout) getWindow().findViewById(R.id.ln_layout);
Button btn = new Button(this);
btn.setText("Test");
ln.addView(btn);
But this doesn't display anything and it doesn't give me any error. Please give me an idea. how can I add the button to title bar?
make title.xml and design your title : place button etc
on activity
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
you will access to elements on title the same way you do on main layout .using findviewbyid
for avoiding some look problems
<style name="theme">
<item name="android:windowTitleBackgroundStyle">#style/themeTitleBackground</item>
<item name="android:windowTitleSize">65dip</item>
</style>
<style name="themeTitleBackground">
<item name="android:layout_height">wrap_content</item>
</style>
inside androidmanifest
<activity android:theme="#style/theme"
I'm sure this is something simple that I am overlooking but I can't figure it out. I have a ListView using a custom adapter with a simple layout and my padding value seems to be ignored. Here's how I want the layout to be:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="#style/Widget.Layout.ComponentEntry" android:padding="#dimen/preferred_padding">
<include layout="#layout/component_entry_summary" />
</LinearLayout>
But the padding is ignored. If I use a nested LinearLayout then it works but the inner LinearLayout seems pointless. This works:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="#style/Widget.Layout.ComponentEntry">
<LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:padding="#dimen/preferred_padding">
<include layout="#layout/component_entry_summary" />
</LinearLayout>
</LinearLayout>
The first layout works outside of a ListView so I'm stumped. For reference here is the style used (which also specifies a padding):
<style name="Widget">
<item name="android:textAppearance">#style/TextAppearance</item>
</style>
<style name="Widget.Layout">
<!-- Empty Style -->
</style>
<style name="Widget.Layout.ListViewItem">
<item name="android:background">#drawable/listview_item_background</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">match_parent</item>
<item name="android:padding">#dimen/preferred_padding</item>
</style>
<style name="Widget.Layout.ComponentEntry" parent="Widget.Layout.ListViewItem">
<item name="android:layout_height">#dimen/listview_item_height</item>
</style>
And the included layout:
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<ImageView android:id="#+id/iconImage"
android:layout_gravity="center_vertical"
android:layout_height="#dimen/icon_size"
android:layout_width="#dimen/icon_size"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher" />
<LinearLayout android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:paddingLeft="#dimen/preferred_padding"
android:orientation="vertical">
<TextView android:id="#+id/topText"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingLeft="#dimen/preferred_padding"
android:singleLine="true"
android:text="#string/app_name"
android:textColor="#color/header_text_enabled"
android:textStyle="bold" />
<TextView android:id="#+id/bottomText"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="#dimen/preferred_padding"
android:singleLine="true"
android:text="#string/app_name"
android:textColor="#color/header_text_enabled" />
</LinearLayout>
</merge>
Here's how layout is inflated (I was originally supplying a null parent and thought that was the issue but it doesn't seem to be:
public View getView(int position, View view, ViewGroup parent) {
ViewHolder viewHolder;
if (view == null) {
view = _layoutInflater.inflate(_layoutResourceId, parent, false);
...
I ran into the same with issue,when I removed the code to set the background the padding worked.
Edit: Found out what is causing it, it is the padding line in the 9 patch images, I thought if you left it out of the drawing it would use the padding in the layout xml. But it actually then uses the stretchable area also as the drawable area.
If the padding lines are not included, Android uses the left and top lines to define this drawable area, effectively defining the padding.
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
Removing the background caused the padding on the outer LinearLayout to start working. Haven't dug into why yet but the problem is (partially) resolved at least.