How to open Activity as a dialog with ActionBar - android

I want to open activity as dialog
public class MoveActivity extends Activity {
private ListView list;
private DocAdapter adapter;
private ArrayList<Dictionary<String, String>> mlist;
DatabaseHelper helper;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_move);
list = (ListView) findViewById(R.id.list);
helper = ApplicationClass.getDatabaseHelperInstance();
helper.open(DatabaseHelper.readMode);
mlist = helper.getDocList();
helper.close();
adapter = new DocAdapter(this, mlist);
list.setAdapter(adapter);
}
}

For using action bar in Dialog, you have to create a custom theme in your style.xml with parent as "Theme.AppCompat.Light".
<style name="PopupTheme" parent="Theme.AppCompat.Light">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
And add this style in your manifest with activity tag:
<activity
android:name=".MyActivity"
android:configChanges="orientation|keyboardHidden|locale"
android:screenOrientation="portrait"
android:theme="#style/PopupTheme" >
and last add this code in your activity before setConytentView(layoutID);
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_ACTION_BAR);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
LayoutParams params = this.getWindow().getAttributes();
params.alpha = 1.0f;
params.dimAmount = 0.5f;
this.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
// This sets the window size, while working around the IllegalStateException thrown by ActionBarView
this.getWindow().setLayout(600,900);
setContentView(R.layout.dialog_move);
}

to Start activity as dialog i defined in AndroidManifest.xml
<activity android:theme="#android:style/Theme.Dialog" />

in the manifest file define theme for activity as dialog.
<activity android:theme="#android:style/Theme.Dialog" />

Related

Hide title and action bar for splash screen and remove White screen in start

I want to remove title and ActionBar on top of my splash activity. I tried the below code,
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mSplashThread.start();
but its not working
anyone can help , why this does not work?
// try this way
//add to AndroidManifest for SplashScreen
<activity
android:name="<YOUR_PACKAGENAME.ACTIVITY>"
android:theme="#style/AppTheme.NoActionBar"
.........../>
//add this styles to styles.xml
<style name="AppTheme.NoActionBar">
<item name="android:background">#android:color/transparent</item>
<item name="android:windowDisablePreview">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#null</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
//add this code to Activity
public class SplashScreen extends AppCompatActivity {
.
.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
.
.
.
}
}

NumberPicker - array of String with 2 lines

I have a NumberPicker, where i want to return 2 lines instead of singleline.
so far i have tried to use \n and created a custom style for NumberPicker.
style.xml
<style name="AppTheme.Picker" parent="AppTheme.Picker" >
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textSize">12dp</item>
<item name="android:maxLines">2</item>
<item name="android:singleLine">false</item>
</style>
my main_acivity.xml file
<NumberPicker
android:theme="#style/AppTheme.Picker"
android:id="#+id/card_options"
android:layout_width="match_parent"
android:layout_height="match_parent">
</NumberPicker>
and the activity class
public class CardOptions extends Activity {
NumberPicker cardOptions;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
cardOptions = (NumberPicker) findViewById(R.id.card_options);
cardOptions.setMinValue(1);
cardOptions.setMaxValue(2);
cardOptions.setDisplayedValues(new String[]{"red\nblue", "green\nYellow"});
}
}
Can anyone help with this?

the status bar changes it's color to black inside fullscreen dialog fragment android

I'm using dialog fragment. The problem is that the status bar color is changed to black. How to change it to some other color? It's strange cause inside fragment, activity it works fine. Its only black inside DialogFragment
#Override
public void onStart() {
super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point
Dialog d = getDialog();
if (d != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
d.getWindow().setLayout(width, height);
d.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Dialog dialog = new Dialog(getActivity(), R.style.full_screen_dialog);
return dialog;
}
You have to set FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDSto indicate that this Window is responsible for drawing the background for the system bars.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
dialog.getWindow().setStatusBarColor(yourColor);
}
I just posted the solution to this problem here
Add following theme to res/value-v21/style
<style name="DialogTheme" parent="#style/Base.Theme.AppCompat.Light.Dialog">
<item name="android:windowTranslucentStatus">true</item>
</style>
And then apply Style on DialogFragment in onCreate
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.DialogTheme);
}
GUYS THE BEST SOLUTION IS IN THE WEBSITE LINK I AM POSTING HERE
https://zocada.com/android-full-screen-dialogs-using-dialogfragment/
I'll also upload the code here for reference
1st create a style FullScreenDialogStyle in your style file :
<style name="FullScreenDialogStyle" parent="Theme.AppCompat.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorPrimary">#color/colorPrimary</item>
<!-- Set this to true if you want Full Screen without status bar -->
<item name="android:windowFullscreen">false</item>
<item name="android:windowIsFloating">false</item>
<!-- This is important! Don't forget to set window background -->
<item name="android:windowBackground">#color/colorWhite</item>
<!-- Additionally if you want animations when dialog opening -->
<!--<item name="android:windowEnterAnimation">#anim/slide_up</item>-->
<!--<item name="android:windowExitAnimation">#anim/slide_down</item>-->
</style>
inside your dialogFragment class override a method onCreate
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL,R.style.FullScreenDialogStyle);
}
then override Onstart method, through which u can access the getDialog() and set the height and width
#Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
dialog.getWindow().setLayout(width, height);
}
}
To change Status Bar Color under DialogFragment, set below style to your dialogFragment under onCreate Method.
like:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NO_TITLE,R.style.FullScreenDialogWithStatusBarColorAccent)
}
Add this style in style.xml
<style name="FullScreenDialogWithStatusBarColorAccent">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="android:statusBarColor">#color/colorAccent</item>
<!--<item name="android:windowAnimationStyle">#style/MateriDocumentAlertsActivityalDialogSheetAnimation</item>-->
</style>
here is the solution i found:
add this to your style.xml file
<style name="BottomSheetDialogTheme" parent="BaseBottomSheetDialog">
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
<!-- set the rounded drawable as background to your bottom sheet -->
<style name="BottomSheet" parent="#style/Widget.Design.BottomSheet.Modal">
<item name="android:background">#color/transparent</item>
</style>
<style name="BaseBottomSheetDialog" parent="#style/Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="bottomSheetStyle">#style/BottomSheet</item>
</style>
then you should override onCreate() method in BottomSheetDialogFragment class and call:
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.BottomSheetDialogTheme);
}
in kotlin
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window?.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window?.statusBarColor = Color.parseColor("#0173B7")
}
A little late to the party but setting IS_FLOATING flag worked for me.
<style name="MyTheme.AlertDialog.FullScreen" parent="MyTheme.AlertDialog">
<item name="windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowAnimationStyle">#style/Animation.AppCompat.Dialog</item>
<item name="android:windowBackground">#color/white</item>
</style>

Action Bar Back Button is not showing in Android

Hi I have created an activity which extends ActionBarActivity & using material theme in my application. In the Action Bar, Back button is not showing.
I didn't find why it is not showing. Any help ?
public class RegistrationActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_background_light));
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!--Support Library compatibility-->
<item name="actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<!-- ActionBar styles -->
<style name="MyTheme.ActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar">
<!--Support Library compatibility-->
<item name="titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
</style>
AndroidManifest.xml
<activity
android:name=".RegistrationActivity"
android:label="#string/title_activity_registration" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".HomeScreenActivity" />
</activity>
Thanks in advance.
add the property
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
to show the "back button"
If the Jorgesys's solution not worked for you. Try overriding the onOptionsItemSelected method.
public class MyActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == android.R.id.home)
{
onBackPressed();
return true;
}
else
{
return super.onOptionsItemSelected(item);
}
}
}
there might be a problem with your toolbar theme:
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Light"

Activity theme appears different than other Activities of the application

Hello I am working on an android application. I am showing the ProgressDialog when perform the network operation in an application. But theme of ProgressDialog appears different in different activities.
<activity
android:name="teemwurk.android.ClockActivity"
android:label="#string/title_activity_clock"
android:screenOrientation="portrait"
android:theme="#style/CustomTheme" >
</activity>
customtheme.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground </item>
<item name="android:windowTitleSize">60dp</item>
</style>
<style name="WindowTitleBackground">
<item name="android:padding">0px</item>
<item name="android:background">#F3F8FB</item>
</style>
</resources>
ClockActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // requesting to set
// the custom title
// bar
setContentView(R.layout.activity_clock);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
// set the back button on click listener
((TextView)findViewById(R.id.backTextView)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
}
TeemWurkAsyncTask.java
public class TeemWurkAsyncTask extends AsyncTask<String, Void, String> {
private ProgressDialog mProgressDialog;
private Context mContext;
private TaskCompleteListener taskCompleteListener;
private int method;
private String TAG = "TeemWurkAsyncTask";
public TeemWurkAsyncTask(TaskCompleteListener taskCompleteListener, int method, Context mContext) {
this.taskCompleteListener = taskCompleteListener;
this.method = method;
this.mContext = mContext;
}
#Override
protected void onPreExecute() {
// display the progress dialog
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog.setTitle(mContext.getString(R.string.app_name));
mProgressDialog.setMessage(mContext.getString(R.string.please_wait));
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(false);
mProgressDialog.setIndeterminate(true);
mProgressDialog.show();
}
But I want it should appear like below this ProgressDialog
Thanks in advance.
Try this .You should change this
<style name="CustomTheme" parent="android:Theme">
........
</style>
to
<style name="CustomTheme" parent="#android:Theme.Holo.Light">
........
</style>
Try this..
Change this..
<style name="CustomTheme" parent="android:Theme">
to
<style name="CustomTheme" parent="#style/AppTheme">
EDIT
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomTheme" parent="#style/AppTheme">
<item name="newStyle">#style/CustomThemeStyle</item>
</style>
<style name="CustomThemeStyle" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground </item>
<item name="android:windowTitleSize">60dp</item>
<item name="android:windowActionBar">false</item>
</style>
<style name="WindowTitleBackground">
<item name="android:padding">0px</item>
<item name="android:background">#F3F8FB</item>
</style>
</resources>
EDIT
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="newStyle" format="reference" />
</resources>

Categories

Resources