In my application I want to use the Theme.NoTitleBar, but on the other hand I also don't want to loose the internal Theme of the Android OS.. I searched on the net and Found the following answer.. I have modified my styles.xml and added the following line of code..
Inside values/styles.xml
<style name="Theme.Default" parent="#android:style/Theme"></style>
<style name="Theme.NoTitle" parent="#android:style/Theme.NoTitleBar"></style>
<style name="Theme.FullScreen" parent="#android:style/Theme.NoTitleBar.Fullscreen"></style>
Inside values-v11/styles.xml
<style name="Theme.Default" parent="#android:style/Theme.Holo"></style>
<style name="Theme.NoTitle" parent="#android:style/Theme.Holo.NoActionBar"></style>
<style name="Theme.FullScreen" parent="#android:style/Theme.Holo.NoActionBar.Fullscreen"></style>
Inside values-v14/styles.xml
<style name="Theme.Default" parent="#android:style/Theme.Holo.Light"></style>
<style name="Theme.NoTitle" parent="#android:style/Theme.Holo.Light.NoActionBar"></style>
<style name="Theme.FullScreen" parent="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen"></style>
In the application tag of the Manifest file I have added an attribute of:
android:theme="#style/Theme.NoTitle"
But when I try to run the code The images in my application gets Blurry.. But when I use the following tag:
android:theme="#android:style/Theme.NoTitleBar"
or
android:theme="#android:style/Theme.Light.NoTitleBar"
or
android:theme="#android:style/Theme.Black.NoTitleBar"
The images in the application comes in the correct form... But In this case I lose all the themes on the new Android OS..
Please help me how can I use NoTitleBar Theme without loosing the Images and the Native Theme..
Code for the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<include
android:id="#+id/main_top_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="#layout/top_bar_title" />
<RelativeLayout
android:id="#+id/container_bar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/main_top_bar"
android:layout_marginTop="-3dp"
android:background="#drawable/tab_nav_bar" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/container_bar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/container_bar1"
android:background="#drawable/location_nav_bar" >
<TableLayout
android:id="#+id/map_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:paddingBottom="5dp"
android:background="#drawable/map_bar_bg" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/MapPointer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:background="#drawable/map_pointer" />
<TextView
android:id="#+id/MapSeperator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:text="|"
android:textColor="#979ca0"
android:textSize="20dp" />
<com.pnf.myevent.CustomTextView
android:id="#+id/DisplayLocation"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="5dp"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#adabad"
android:textSize="12dp" />
<Button
android:id="#+id/RefreshBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:background="#drawable/refresh_button" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/calendar_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp" >
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/MonthBtn"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/month_button" />
<Button
android:id="#+id/TodayBtn"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/today_button" />
<Button
android:id="#+id/WeekBtn"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/week_button" />
</TableRow>
</TableLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/container_bar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/container_bar2"
android:background="#drawable/cal_nav_bar" >
<Button
android:id="#+id/CalPrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="5dp"
android:background="#drawable/left_arrow_button" />
<com.pnf.myevent.CustomTextView
android:id="#+id/CalTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:shadowColor="#ffffff"
android:shadowDx="0"
android:shadowDy="2"
android:shadowRadius="1"
android:text="Title"
android:textColor="#666666"
android:textSize="15dp" />
<Button
android:id="#+id/CalNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:layout_marginTop="5dp"
android:background="#drawable/right_arrow_button" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/container_bar4"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/container_bar3"
android:background="#c8c9cc" >
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:horizontalSpacing="2dp"
android:listSelector="#00000000"
android:numColumns="7"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/footer_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/container_bar4" >
<ListView
android:id="#+id/CalendarList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:listSelector="#00000000"
android:cacheColorHint="#00000000"
android:divider="#dedede"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false" />
</RelativeLayout>
if you want the original style of your Ui to remain and the title bar to be removed with no effect on that, you have to remove the title bar in your activity rather than the manifest. leave the original theme style that you had in the manifest and in each activity that you want no title bar use this.requestWindowFeature(Window.FEATURE_NO_TITLE); in the oncreate() method before setcontentview() like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_signup);
...
}
To Hide the Action Bar add the below code in Values/Styles
<style name="CustomActivityThemeNoActionBar" parent="#android:style/Theme.Holo.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
Then in your AndroidManifest.xml file add the below code in the required activity
<activity
android:name="com.newbelievers.android.NBMenu"
android:label="#string/title_activity_nbmenu"
android:theme="#style/CustomActivityThemeNoActionBar">
</activity>
In your manifest use:-
android:theme="#style/AppTheme" >
in styles.xml:-
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
Surprisingly this works as yo desire, Using the same parent of AppBaseTheme in AppTheme does not.
Why are you changing android os inbuilt theme.
As per your activity Require You have to implements this way
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
as per #arianoo says you have to used this feature.
I think this is better way to hide titlebar theme.
In your styles.xml, modify style "AppTheme" like
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
use android:theme="#android:style/Theme.NoTitleBar in manifest file's application tag to remove the title bar for whole application or put it in activity tag to remove the title bar from a single activity screen.
this.requestWindowFeature(getWindow().FEATURE_NO_TITLE);
Related
I want to implement a second activity that is on top of the first one, with the first one still visible. But there's no real good documentation about it.
I already made the second activity and used
android:theme="#style/Theme.AppCompat.Light.Dialog"
in the manifest but this shows only the name of the app without the content.
I made sketch of what I mean.
EDIT: the solution was to add a theme to the styles.xml
<style name="CustomDialog" parent="Base.Theme.AppCompat.Light.Dialog.MinWidth">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
and to specify the width and height in dp in the second activity xml file.
You have to do a few things to be able to do this:
First make a custom style for your Activity.
<style name="AppDialogTheme" parent="#style/AppTheme.NoActionBar">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Then add the newly created style to the Android Manifest:
<activity
android:name="Activity2"
android:theme="#style/AppDialogTheme" />
And finally create your layout by making the parent ViewGroup for example a FrameLayout set the background also to #android:color/transparent. Now include your layout inside the FrameLayout and add the padding you want to get that Dialog look.
Hope that helps!
Styles
<style name="DialogActivity" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
Manifest
<activity
android:name="MyActivity"
android:excludeFromRecents="true"
android:theme="#style/DialogActivity" >
This will work exactly the way you want.
You cannot have multiple activities running at the same time, so Why not use custom dialog?
For example, create dialogClass:
public class ProgressDialog extends Dialog {
public ProgressDialog(#NonNull Context context) {
super(context);
setContentView(R.layout.progress_dialog); //this is your layout for the dialog
}
}
And all you need to do is to create dialog instant and call it like this:
ProgressDialog progressDialog = new ProgressDialog(getContext());
progressDialog.show(); // this line shows your dialog
And you will have your custom layout over your activity.
Open Another view on Activity We have used Dialogs , You can use dialog with custom layout
Like this:
final Dialog dialog=new Dialog(FirstActivity.this);
dialog.setContentView(R.layout.dialog_custom);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
LinearLayout
rebooking_back_button_ll=dialog.findViewById(R.id.rebooking_back_button_ll);
rebooking_back_button_ll.setOnClickListener(
new View.OnClickListener(){
#Override
public void onClick(View v){
dialog.dismiss();
}
});
dialog.show();
dialog_custom.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="wrap_content"
android:background="#android:color/transparent"
android:orientation="vertical"
app:layout_constraintHeight_max="wrap">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/title"
android:background="#color/colorPrimary"
android:gravity="center"
android:text="Custom Activty"
android:textAlignment="center"
android:textColor="#android:color/white"
android:textSize="14sp" />
<LinearLayout
android:id="#+id/time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/back_ll"
android:layout_below="#+id/content"
android:orientation="vertical">
<TextView
android:id="#+id/rebooking_single_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="book a single appointment"
android:textAlignment="center"
android:textColor="#9C27B0"
android:textSize="16sp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="90dp"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go next"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/end_time_recycle"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#d9d8d8" />
<TextView
android:id="#+id/rebooking_recurring_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="Check Balance"
android:textAlignment="center"
android:textColor="#9C27B0"
android:textSize="16sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/back_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/end_time_recycle"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#d9d8d8" />
<LinearLayout
android:id="#+id/rebooking_back_button_ll"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FF5722"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Back"
android:textColor="#android:color/white"
android:textSize="17sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
I am facing a problem of getting null in getSupportActionBar(),
when setting toolbar as actionbar in an activity and setting the back button programmatically from supportActionBar, the exception I get is,
Attempt to invoke virtual method 'void android.app.ActionBar' on a null object reference
here is the xml view of the activity, the toolbar is included from another layout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar_ftp"
android:id="#+id/include" />
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="#+id/include"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_alignParentBottom="true"
android:id="#+id/below_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:background="#color/white">
<TextView
android:layout_below="#+id/line11"
android:id="#+id/txt_search_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_margin="16dp"
android:text="#string/search_by_Date"/>
<RelativeLayout
android:id="#+id/rl_cal_pick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_search_date"
>
<ImageView
android:id="#+id/icon_secheudel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/rlBoxtime"
android:layout_alignBottom="#+id/rlBoxtime"
android:src="#mipmap/ic_clock_red"
android:tint="#color/colorPrimary"/>
<RelativeLayout
android:id="#+id/rlBoxtime"
android:layout_toRightOf="#+id/icon_secheudel"
android:background="#drawable/blue_out_line"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="3dp"
android:paddingTop="3.5dp"
android:paddingBottom="3.5dp"
android:layout_marginLeft="0dp">
<TextView
android:id="#+id/txt_chosen_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:minWidth="30dp"
android:text=""/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_toRightOf="#+id/txt_chosen_date"
android:layout_centerVertical="true"
android:src="#mipmap/ic_calendar_schedule"
android:tint="#color/colorAccent"
android:layout_marginRight="2.5dp"/>
</RelativeLayout>
</RelativeLayout>
<TextView
android:id="#+id/btn_tommorow"
android:text="#string/tommorow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:gravity="center"
android:layout_alignTop="#+id/rl_cal_pick"
android:layout_alignBottom="#+id/rl_cal_pick"
android:layout_toRightOf="#+id/tvTOday"
android:textColor="#color/colorAccent"
android:padding="5dp"
android:background="#drawable/blue_out_line"
style="#style/borderless_blue_text_button"
/>
<TextView
android:id="#+id/tvTOday"
android:text="#string/today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:gravity="center"
android:padding="5dp"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/rl_cal_pick"
android:layout_alignBottom="#+id/rl_cal_pick"
android:layout_toRightOf="#+id/rl_cal_pick"
android:textColor="#color/colorAccent"
android:background="#drawable/blue_out_line"
android:layout_marginRight="8dp"/>
</RelativeLayout>
</RelativeLayout>
Here is the toolbar_ftp.xml file
<android.support.v7.widget.Toolbar 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:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Light">
<ImageView
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:scaleType="centerInside"
android:src="#drawable/ftp_home_logo"
tools:ignore="ContentDescription" />
</android.support.v7.widget.Toolbar>
Here is the toolbar code
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
hi try to change theme style of your app
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="android:textColor">#color/black</item>
<item name="android:actionOverflowButtonStyle">#style/ActionButtonOverflow</item>
</style>
I tried all the solutions posted here, Still, I was experiencing the crash. Later I figured out the problem, It was because of giving an additional id in the include statement of the xml view.
<include layout="#layout/toolbar_ftp"
android:id="#+id/include" />
When referencing the toolbar, it became ambiguous for id inside id.
In most of the cases this problem can be caused by your theme. Check it again, and make sure that it's parent with Theme.AppCompat.Light.DarkActionBar.
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">true</item>
...
</style>
If your activity extends AppCompatActivity or ActionBarActivity, then you must call getSupportActionBar().
if you are using AppcompatActivity try this :
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if you are using ActionBarActivity then try this :
this.getActionBar().setDisplayHomeAsUpEnabled(true);
I have the following layout for my custom log in dialog
<?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"
android:padding="#dimen/padding_large">
<ImageButton android:src="#drawable/ic_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dialog.login.settings"
android:padding="#dimen/margin_medium" />
<TextView android:text="#string/dialog.login.text.user_name"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/dialog.login.user_name"
android:layout_width="match_parent"
android:gravity="center"
android:ems="20"
android:layout_height="wrap_content"
android:inputType="text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView android:text="#string/dialog.login.text.password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/dialog.login.password"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox android:id="#+id/dialog.login.show_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/dialog.login.check.show_password"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_margin="#dimen/margin_medium"
android:checked="false" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:id="#+id/dialog.login.cancel"
android:drawableStart="#drawable/ic_exit_black"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/margin_medium"
android:text="#string/dialog.login.button.cancel" />
<Button android:id="#+id/dialog.login.connect"
android:text="#string/dialog.login.button.connect"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_marginStart="#dimen/margin_medium"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
when I create the dialog and setcontentview the width of the dialog becomes equal to that of the image button on the first row
if I remove that , it becomes the size of the EditText (dialog.login.user_name) whose ems is 20
when I make the dialog's constructor call the base dialog constructor with a theme of R.style.Theme.Material.Dialog it does get the correct (about 3/4 of the screen) but the problem is that it ignores my primary and accent colours (which is normal)
Is there a way to have the dialog have the Theme.Material.Dialog size but still keep my own primary/accent colours?
thanks in advance for any help you can provide
After a lot of searching it seems that the solution is to actually replace the dialogTheme attribute of my main theme, so the solution was:
<style name="app.theme"
parent="android:Theme.Material.Light.NoActionBar.Fullscreen">
<item name="android:dialogTheme">#style/app.dialog</item>
......
</style>
<style name="app.dialog"
parent="android:Theme.Material.Light.Dialog">
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary.dark</item>
<item name="android:colorAccent">#color/accent</item>
</style>
I have just started using Android Studio on Mac. The buttons I have created are showing as text on the AVD. Can anyone help me to fix this?
Thank you. It looks correct while rendering in the Design window.
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="188dp"
android:layout_marginRight="67dp"
android:onClick="speakText"
android:text="#string/Speak"
android:clickable="true"
/>
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="81dp"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/buttonSpeaker"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/button1"
android:layout_toStartOf="#+id/button1"
android:clickable="true"/>
Similar to the material design. You can inherit you theme in style.xml like this
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
Or overide global button style like this
in AppTheme:
<item name="android:buttonStyle">#style/customButtonStyle</item>`
and in style.xml
<style name="customButtonStyle" parent="#android:style/Widget.Button">
<!-- Customize your button style here. -->
</style>
I'm in the middle of modifying a test message application and one of the features that I'd like to add to it would be that when a text message is received, a dialog box of some sort would pop up with the text message stuff and the ability to quickly reply to it, all without having to go into the actual application. Taking HandcentSMS as an example, here is what I'm talking about:
Any ideas how to go about doing this, or could anyone point me in a good direction to get started on this?
You can make an activity, and style it with custom style which should inherit Theme.Dialog
Example style:
<style name="Theme.MyDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">#android:drawable/alert_light_frame</item>
<item name="android:textColorPrimary">#android:color/black</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:overScrollMode">never</item>
<item name="android:windowNoTitle">true</item>
</style>
The most important thing is to prepare xml layout of the activity properly.
I suggest to WRAP_CONTENT for everything vertically, and FILL_PARENT horizontally.
Sample layout xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="280dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/frg_alert_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/topbar_logo"
android:drawablePadding="10dp"
android:gravity="center_vertical"
android:padding="10dp"
android:text="Title"/>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#android:drawable/divider_horizontal_bright"/>
</LinearLayout>
<FrameLayout
android:id="#+id/customPanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone">
<FrameLayout
android:id="#+id/custom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
<ScrollView
android:id="#+id/messagePanel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:padding="10dp">
<TextView
android:id="#android:id/message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Some text"/>
</ScrollView>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#android:drawable/divider_horizontal_bright"/>
<LinearLayout
android:id="#+id/frg_alert_three_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:visibility="gone"
android:weightSum="3">
<Button
android:id="#+id/button_positive"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:maxLines="2"
android:minLines="2"
android:text="Button"/>
<Button
android:id="#+id/button_neutral"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:maxLines="2"
android:text="Button"/>
<Button
android:id="#+id/button_negative"
style="?android:attr/buttonStyle"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:maxLines="2"
android:text="Button"/>
</LinearLayout>
<LinearLayout
android:id="#+id/frg_alert_two_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="#dimen/screenPadding"
android:weightSum="2">
<Button
android:id="#+id/button_positive"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="2"
android:minLines="2"
android:text="Button"/>
<Button
android:id="#+id/button_negative"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:maxLines="2"
android:minLines="2"
android:text="Button"/>
</LinearLayout>
</LinearLayout>
for Create this UI just Create an Activity with background transparent as:
Step 1: add res\values\style.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Smspopuptheme" parent="android:style/Theme.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:background">#android:color/transparent</item>
</style>
</resources>
Step 2: add theme to in AndroidManifest.xml for activity which u want to show with message as:
<activity
android:label="#string/app_name"
android:theme="#style/Theme.D1NoTitleDim"
android:name=".SmspopuptestActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Step 3: In SmspopuptestActivity.java set FEATURE_NO_TITLE before setContentView as:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
//this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
Step 4: Your Activity layout look like res/layout/main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#55000000"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/frg_alert_buttons"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="#android:color/darker_gray"
android:gravity="center"
android:padding="5dp"
android:layout_centerInParent="true"
android:weightSum="3">
</LinearLayout>
</LinearLayout>
add your layout elements in frg_alert_buttons likes Buttons, Textviews,Imageview and EditViews as per your need.
Start SmspopuptestActivity.java Activity when you receive new SMS.
Some helpful resources:
android-listen-for-incoming-sms-messages
SOME SOUCE CODE FOR SMSPOPUP IN ANDROID:
droid-notify
android-smspopup
showsms
smspopup-for-android