I have been trying to alter my AlertDialog so that it will show the text right justified (for Hebrew).
With inazaruk's help here: Right justify text in AlertDialog
I managed to get the dialog showing but it only works correctly in the emulator (Eclipse).
When I move it onto my device (Xpersia X10a) the alert box appears at the top of the screen with the background blocking out everything behind it.
The image on the emulator:
The image on my device:
Code:
public class test extends Activity {
/** Called when the activity is first created. */
public class RightJustifyAlertDialog extends AlertDialog {
public RightJustifyAlertDialog(Context ctx) {
super(ctx, R.style.RightJustifyTheme); } }
#Override
public void onCreate(Bundle savedInstanceState) {
final Context con = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog dialog = new RightJustifyAlertDialog(con);
dialog.setButton("button", new OnClickListener(){
public void onClick(DialogInterface arg0, int arg1)
{
}
});
dialog.setTitle("Some Title");
dialog.setMessage("Some message");
dialog.show();
}
});
}
}
Styles:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="RightJustifyTextView" parent="#android:style/Widget.TextView">
<item name="android:gravity">right|center_vertical</item>
<item name="android:layout_centerVertical">true</item>
</style>
<style name="RightJustifyDialogWindowTitle" parent="#android:style/DialogWindowTitle" >
<item name="android:gravity">right|center_vertical</item>
<item name="android:layout_centerVertical">true</item>
</style>
<style name="RightJustifyTheme" parent="#android:style/Theme.Dialog.Alert">
<item name="android:textViewStyle">#style/RightJustifyTextView</item>
<item name="android:windowTitleStyle">#style/RightJustifyDialogWindowTitle</item>
</style>
</resources>
My device is working with Android 2.1-update1 and the emulator is set to same.
One simple thing to rule out... Check you device's other apps to see if all of them have had their AlertDialog background alpha transparencies removed. You can try deleting something in the default mail application, or other applications that also have a long press delete for items. I wouldn't see the need to change this styling, but you never know what Carriers are going to do these days.
Related
I have a BottomSheetDialogFragment which has two buttons in it and when I click on any button dismiss() method is called. Is there a way by which I can animate BottomSheetDialogFragment. I want it to show a slow sliding down animation with a duration of 1000ms.
Sample code
signin.findViewById(R.id.signin_button_using).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
callback.onClickSignInEmail();
dismiss();
}
})
In your fragment which is extended with BottomSheetDialogFragment, try overriding this method like this
#Override
public void onActivityCreated(Bundle arg0) {
super.onActivityCreated(arg0);
getDialog().getWindow()
.getAttributes().windowAnimations = R.style.DialogAnimation;
}
DialogAnimation can be defined in the styles like this
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">#anim/slide_up</item>
<item name="android:windowExitAnimation">#anim/slide_down</item>
</style>
Further, slide_up and slide_down would be your implementation of required animation. You can find plenty of example for the same online.
I am trying to change the color of the background in my android app. At the moment when I press the button it changes the color for that specific activity and not for all the other activities. Is there a way to change it for the whole app?
public class colorPicker extends AppCompatActivity {
View view;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_color_picker);
view = this.getWindow().getDecorView();
}
public void goPink(View v){
view.setBackgroundResource(R.color.Pink);
}
public void goGreen(View v){
view.setBackgroundResource(R.color.Green);
}
public void goYellow(View v){
view.setBackgroundResource(R.color.Yellow);
}
}
create a theme in your styles.xml and add following to that theme
<item name="android:windowBackground">#color/window_background
and set android:theme="#style/YourTheme" in your
<application>
...
</application
in manifest file
In this case, You need to add few changes in your activity.
In on onCreate
if(getIntent().getExtras() != null)
{
int theme = getIntent().getIntExtra("theme", R.style.AppTheme);
setTheme(theme);
getApplication().setTheme(theme);
//recreate();
}
Condition onCLick
if(condition)
getIntent().putExtra("theme", R.style.AppTheme2);
else
getIntent().putExtra("theme", R.style.AppTheme);
and maintain 2 theme
<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary"></item></style>
and the second theme similar to it just change the name as BaseTheme2.
But this is not suggested to change the app theme at runtime.
You could change the window background color of your app theme and don't use a background for activities or you can use a transparent background for activities.
When you start android app Main activity starts with white background and black header with your app name in left corner. Like this
How to wholly remove this (when app is started not to show this) and add custom loading progress bar or some logo to the screen?
How about creating a splash dialog with custom layout containing progress bar?
In your main activity do something like this
private SplashDialog mSplashDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showSplashScreen();
setContentView(R.layout.yourmainlayout);
}
protected void removeSplashScreen() {
if (mSplashDialog != null) {
mSplashDialog.dismiss();
mSplashDialog = null;
}
}
protected void showSplashScreen() {
mSplashDialog = new SplashDialog(this, R.style.splash_dialog);
mSplashDialog.setCancelable(false);
mSplashDialog.show();
}
Create custom dialog
public class SplashDialog extends Dialog {
private ProgressBar mProgressBar;
public SplashDialog(Context context, int theme) {
super(context, theme);
setContentView(R.layout.splash_dialog);
mProgressBar = (ProgressBar) findViewById(R.id.splash_progress);
}
public void setProgress(int progress) {
mProgressBar.setProgress(progress);
}
}
And add style to that will let dialog fill all screen.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="splash_dialog">
<item name="android:padding">0dp</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowFrame">#null</item>
</style>
</resources>
To change dialog's progress value call mSplashDialog.setProgress(int progress).
When your data is loaded call removeSplashScreen().
I think what you're looking for can be found here:
how to change the splash screen
What worked for me (since I don't have much load up on start actually I didn't need splash screen at all) is changing res/values/styles.xml :
<resources>
<color name="custom_theme_color">#000000</color>
<style name="AppTheme" parent="android:Theme.Light" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/custom_theme_color</item>
</style>
</resources>
It just start with black screen witch goes to full screen (after 1-2 sec) when it is all loaded.
It looks very "profesional".
I create many activities and classes in my app. However I have a function to change font size and color in every activity. This function changes text in own activity. When I go to other activity I must change textSize and color again. How can I create a function to change TextView in many classes and activities in one shot?
My app Structure:
Main.java main.xml/
Suad1.java suad1.xml/
Suad2.java suad2.xml/
Suad3.java suad3.xml/
Suad4.java suad4.xml/
I want to change these activity in one time. Here my code in Suad1.class.
public void ShowDialog() {
final AlertDialog.Builder popDialog = new AlertDialog.Builder(this);
final SeekBar seek = new SeekBar(this);
seek.getProgress();
seek.setMax(100);
popDialog.setIcon(R.drawable.conp);
popDialog.setTitle(R.string.menu_settings);
popDialog.setView(seek);
try {
seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
subtitles.setTextSize(progress);
}
});
}
catch (Exception e) {
e.printStackTrace();
}
popDialog.setSingleChoiceItems(items , -1,
new DialogInterface.OnClickListener() {
int i;
public void onClick(DialogInterface dialog, int item) {
i = item;
if(items[i] =="Blue") {
subtitles.setTextColor(getResources().getColor(R.color.font3));
} else if(items[i] == "Yellow") {
subtitles.setTextColor(getResources().getColor(R.color.font1));
} else if(items[i]== "Red") {
subtitles.setTextColor(getResources().getColor(R.color.font2));
}
}
}
);
// Button
popDialog.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(Suad1.this, "Your setting is complete", Toast.LENGTH_LONG).show();
dialog.dismiss();
}
}
);
popDialog.create();
popDialog.show();
}
And two more questions:
Can I update SeekBar when out dialog and back again?
Can I have two Titles or more in one AlertDialog?
Create a separate class with method which you can use in multiple Activities for Changing TextView text,color :
public class ChangetextAttr {
public Activity context;
public ChangetextAttr(Activity context){
this.context=context;
}
// Create an Method for Changing TextView Attributes
public void settextViewAttr(Activity activity, TextView txtView){
txtView.setTextSize(15);
txtView.setTextColor(activity.getResources().getColor(R.color.font1));
//....
}
and from Any Activity you can settextViewAttr method for setting TextView Attributes :
ChangetextAttr obj=new ChangetextAttr(Your_Activity.this);
obj.settextViewAttr(this,any_textview_instance);
Hey create a(Customized textview) class which extends TextView and do whatever you want to do for the textview like changing text color and textstyle. now use this class in all your xml's . if your class name MyTextView. then your xml should be like the following...
<urpackage.MyTextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
To answer your questions:
1- What you need is two styles (Bold & normal) and change between the used style for Text using View.setTextAppearance. Check Android documentaion and this answer.
2- To update seekbar with a value that is unchanged from View to View, then you need to keep its progress in a shared preference for e.g. and set the progress in onResume.
3- Consider using a custom Dialog instead (you can define it in XML as you wish). Or you can include /n to have multi lines in the Title string
Android provides you with mechanisms already to change the appearance of widgets, via Styles and Themes.
Here is how you define a style that sets the text size and color of any view that holds text:
<style name="BigColoredText">
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">25sp</item>
</style>
and here is how you apply it to a TextView:
<TextView style="#style/BigColoredText" .../>
Styles can only be supplied to Views at construction time, you cannot change it afterwards. However, you can programmatically change the textAppearance with is the subset of a style that refers to text attributes via:
TextView v = ...;
v.setTextAppearance(R.styles.BigColoredText);
Now, if you want all TextViews within your Activity or Application using that same style (or at least use it by default), then you need a Theme:
<style name="Theme.MyTheme" parent="#android:style/Theme">
<item name="android:textViewStyle">#style/BigColoredText</item>
</style>
and then apply the theme to either the entire Application or one or more Activities in your manifest:
<application or activity android:theme="#style/Theme.MyTheme" .../>
Or you can change it programmatically at runtime via:
Activity activity = ...;
activity.setTheme(R.style.Theme_MyTheme);
So I know you can use your own animation between activities using the overidePendingTransition method. I set up a transition between two activites and it works perfect on my emulator but I see no transition when I flash the app on to my phone. How can this be?
My emulator is running 2.2 as is my phone
Here is my onCreate method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.close);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(ActivityTransitionActivity.this, ActivityTwo.class);
ActivityTransitionActivity.this.startActivity(myIntent);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}
});
}
In your style.xml define your animation
<style name="Animation.CustomAnimation">
<item name="android:activityOpenEnterAnimation">#anim/slide_in_left</item> When opening a new activity, this is the animation that is run on the next activity
<item name="android:activityOpenExitAnimation">#anim/slide_out_right</item>When opening a new activity, this is the animation that is run on the previous activity (which is exiting the screen)
<item name="android:activityCloseEnterAnimation">#anim/slide_in_right</item>When closing the current activity, this is the animation that is run on the next activity (which is entering the screen).
<item name="android:activityCloseExitAnimation">#anim/slide_out_left</item>When closing the current activity, this is the animation that is run on the current activity (which is exiting the screen).
</style>
<style parent="android:style/Theme.Light.NoTitleBar.Fullscreen" name="app_theme">
<item name="android:windowBackground">#drawable/splash</item>
<item name="android:windowAnimationStyle">#style/Animation.CustomAnimation</item>
</style>
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:theme="#style/app_theme">
apply app_theme to your application in android manifest
I had the same problem (on a samsung galaxy s). I found my answer at Activity animation not working in Galaxy Tab
Turns out animations are turned off by default on samsung devices. (It's a setting: Go to Settings -> display -> animations and then turn on the All animations and you will be able to see the animations)
Try this,
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(v.getContext(),
ActivityTwo.class);
startActivityForResult(myIntent, 0);
overridePendingTransition(R.anim.zoomextra, 0);
finish();
}
});