android - Holo button looks different between versions - android

I have an android app with min sdk version 14.
in my values-v14 folder, in styles.xml I have this:
<style name="MyButtonStyle" parent="android:Widget.Holo.Button"></style>
I apply this style to two buttons in one of my activities (the activity looks like a big dialog).
I run the app on:
OnePlus phone (version 4.4.4 - api 19)
GT-I8190 (version 4.1.2 - api 16)
For some reason the buttons look different in color, which is weird because the Holo Theme should be available in API 14 and above (and both phones are above 14).
Small difference but its there (in the OnePlus the buttons are darker and in the GT they are lighter). Why is it like that? shouldn't it be the same?
OnePlus Image:
GT-I8190 Image:
----------------- EDIT - Adding Code --------------------
Here is the xml file with the buttons (not_allowed_dialog.xml).
As you can see, there isn't any drawables in the button or anywhere else.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
android:orientation="vertical" >
<TextView
android:id="#+id/not_logged_in_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Please log in to add a ride"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="25sp" />
<LinearLayout
android:id="#+id/not"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/not_logged_in_text_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dip"
android:orientation="horizontal"
android:paddingBottom="1.0dip"
android:paddingLeft="4.0dip"
android:paddingRight="4.0dip"
android:paddingTop="5.0dip" >
<Button
android:id="#+id/not_allowed_login"
style="#style/MyButtonStyle"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="Login Now!" />
<Button
android:id="#+id/not_allowed_register"
style="#style/MyButtonStyle"
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="Register Now!" />
</LinearLayout>
</RelativeLayout>
Also - Activity code:
public class DialogActivity extends Activity {
private Button toRegisterBtn, toLoginBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.not_allowed_dialog);
setFinishOnTouchOutside(false);
toRegisterBtn = (Button) findViewById(R.id.not_allowed_register);
toLoginBtn = (Button) findViewById(R.id.not_allowed_login);
toRegisterBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(),
RegisterActivity.class);
startActivity(i);
setResult(RESULT_OK, null);
finish();
}
});
toLoginBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(),
LoginActivity.class);
startActivity(i);
setResult(RESULT_OK, null);
finish();
}
});
}
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
}
}

Related

startActivity from BroadcastReceiver Button Views on Activity don't show up

I start my activity alarmAlert.class from onReceive().
The activity was started .
There three buttons and two TextViews on my activity.
when the activity started ,Textviews always show up,
but the buttons not always show up.
I start the activity from my MainActivity ,all the views work
perfect
Anything I can do .
thanks
I got something.
If my App is not running in background (click menu button,remove the app from list)
the activity started from onReceive() , buttons will not show up.
if the App still run in background ,everything is perfect .
my onReceive code:
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
int id = intent.getIntExtra("id", -1);
try{
Intent alertIntent=new Intent();
alertIntent.setClass(context, AlarmAlert.class);
Bundle bundle=new Bundle();
bundle.putInt("id", id);
alertIntent.putExtras(bundle);
alertIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
context.startActivity(alertIntent);
}
catch (Exception e){
AlarmGloble.writeLog(context,"AlarmReceiver:"+e.toString());
}
part of my AlarmAlert code
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
Log.d("AA","onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.alarm_alert);
AlarmGloble.dbHelper=new DBHelper(this,AlarmGloble.DB_NAME,AlarmGloble.DB_VERSION);
AlarmGloble.dbLib=new DataBaseLib(AlarmGloble.dbHelper);
settingFromId();
findViews();
setListener();
updateView();
mVibrator=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
setSystemVolume(0);
//play mp3 by Handler
mHandler.sendMessage(mHandler.obtainMessage(PLAY));
}
private void updateView(){
TextView textViewSnooze=(TextView)findViewById(R.id.alarm_alertTextViewSnooze);
if (mp3Test){
textViewSnooze.setVisibility(View.INVISIBLE);
spinnerSnooze.setVisibility(View.INVISIBLE);
buttonClose.setVisibility(View.INVISIBLE);
buttonEdit.setVisibility(View.INVISIBLE);
}
else {
textViewSnooze.setVisibility(View.VISIBLE);
spinnerSnooze.setVisibility(View.VISIBLE);
buttonClose.setVisibility(View.VISIBLE);
buttonEdit.setVisibility(View.VISIBLE);
if(alarmRept<=0){
textViewSnooze.setVisibility(View.VISIBLE);
spinnerSnooze.setVisibility(View.VISIBLE);
}
else{
textViewSnooze.setVisibility(View.INVISIBLE);
spinnerSnooze.setVisibility(View.INVISIBLE);
if (alarmReptCount<alarmReptTimes)
if (alarmKind==0)
mMessage=mMessage+"\n"+"next alarm :"+mClockSnooze[alarmRept]+" ";
else
mMessage=mMessage+"\n"+"next alarm:"+AlarmGloble.rept[alarmRept]+" ";
}
}
textViewMessage.setText(mMessage);
if(mMp3.equals(AlarmGloble.RANDOM)){
File file=new File(AlarmGloble.ROOT_MUSIC);
RandomMp3 rm=new RandomMp3(file);
if (rm.getCount()>0)
mMp3=rm.getFile();
else
mMp3="";
}
else {
if(mMp3.equals(AlarmGloble.DEFAULT)){
mMp3=getDefaultMP3();
}
else{
String[] s=mMp3.split("/");
textViewSongName.setText(s[s.length-1]);
}
}
if (mMp3.equals("")){
textViewSongName.setText(mMp3);
}
else {
String[] s=mMp3.split("/");
textViewSongName.setText(s[s.length-1]);
}
(LinearLayout)findViewById(R.id.alarm_alertLinearLayoutButtons);
linearLayoutButtons.requestFocus();
}
here is alarm_alert.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linearLayoutAlarmAlert" >
<LinearLayout
android:id="#+id/alarm_alertLinearLayoutButtons"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/alarm_alertButtonClose"
style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnClose" />
<Button
android:id="#+id/alarm_alertButtonEdit"
style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnEdit"
android:visibility="visible" />
<Button
android:id="#+id/alarm_alertButtonDismiss"
style="#style/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btnExit"
android:visibility="visible" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/alarm_alertTextViewSnooze"
style="#style/RedLeft17sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/snooze" />
<Spinner
android:id="#+id/alarm_alertSpinnerSnooze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:id="#+id/alarm_alertTextViewMessage"
style="#style/YellowLeft17sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/btnClose" />
<TextView
android:id="#+id/alarm_alertTextViewSongName"
style="#style/YellowLeft17sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:text="#string/btnClose" />
</LinearLayout>
I can only see 2 buttons buttonClose and buttonEdit in the AlarmAlert Activity, so i'm assuming the 3 buttons that aren't showing are in alarm_alertLinearLayoutButtons.xml which should be reused in alarm_alert.xml as such
<include layout="#layout/alarm_alertLinearLayoutButtons"/>
Ref: http://developer.android.com/training/improving-layouts/reusing-layouts.html
I can't see anything wrong with this except for the last couple of lines.
linearLayoutButtons isn't set.
linearLayoutButtons = (LinearLayout)findViewById(R.id.alarm_alertLinearLayoutButtons);
linearLayoutButtons.requestFocus();

how to show/hide layout on button click

i want to have two relativelayout in first relativelayout have map and in second relativelayout i have the list..,i want on starting only layout with map will be visible on screen with a button,,when i click on button then layout with listview get open from right side with new new button on the top of it,,and prevoius button get hide.and screen get divided with two parts with different layouts..i have done some thing but from starting onward m getting half half screen.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ListView_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1" >
<RelativeLayout
android:id="#+id/rl_ListView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5" >
<Button
android:id="#+id/getdirection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Directions" />
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" >
</fragment>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_ListView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:visibility="invisible" >
<Button
android:id="#+id/hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Directions" />
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:visibility="invisible" />
</RelativeLayout>
</LinearLayout>
MainActivity
show = (TextView)findViewById(R.id.getdirection);
show1 = (TextView)findViewById(R.id.hide);
rt = (RelativeLayout)findViewById(R.id.rl_ListView2);
show.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(rt.getVisibility()==View.INVISIBLE)
{
rt.setVisibility(View.VISIBLE);
}
show.setVisibility(View.INVISIBLE);
}
});
show1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(rt.getVisibility()==View.VISIBLE)
{
rt.setVisibility(View.INVISIBLE);
}
show1.setVisibility(View.INVISIBLE);
}
});
Try this:
You are getting layout1 in half screen from starting due to weight property. You can try not giving weight in starting and give it programatically on button click.
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
button1.setVisibility(View.GONE); //hide old button
layout2.setVisibility(View.VISIBLE); //show layout2
//set Relativelayout 1 to half screen
RelativaLayout.LayoutParams params = layout1.getLayoutParams();
params.weight = 0.5;
layout1.setLayoutParams(params);
}
});
Hope this helps.
Set visibility as Gone instead of Invisible
button.setOnClickListener(this);
public void onClick(View v) {
layoutid.setVisibility(View.GONE);
}
You can try with isShown() as suggested by Amiya
<b>
button2.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
if(button1.isShown()) {
// Your_Staff
}
else{
// Your_Staff
}
}
});
</b>
From my view you did not set the orientation in the LinearLayout to be vertical for the two RelativeLayouts. I also suggests you put the map and Button in a FrameLayout as well instead of RelativeLayout.

Adding custom layout to ActionBarSherlock fails

I am trying to add a Custom Layout to ActionBar using the ActionBarSherlock library.
I find that although there seems to be no error,the Layout is not displayed.
View customView=LayoutInflater.from(this).inflate(R.layout.layout_actionbar_top,null);
ImageButton ab_camera=(ImageButton) customView.findViewById(R.id.ab_camera);
ImageButton ab_gallery=(ImageButton)customView.findViewById(R.id.ab_gallery);
ab_camera.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(getBaseContext(),CameraActivity.class));
}});
ab_gallery.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, IMAGE_REQUEST_CODE);
}});
LayoutParams params=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,Gravity.RIGHT | Gravity.CENTER_VERTICAL);
getSupportActionBar().setCustomView(customView,params);
The Activity instead loads without the custom layout in the ActionBar.
This is the Custom layout,a LinearLayout that is horizontal:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton android:id="#+id/ab_camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_menu_camera"/>
<ImageButton android:id="#+id/ab_gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_menu_gallery"
/>
</LinearLayout>
I had failed to set a flag enabling ActionBarSherlock to display my customView to true.
getSupportActionBar().setDisplayShowCustomEnabled(true);

Ui elements in xml doesn't show up in emulator?

Here is the problem.My UI elements in xml doesn't show up when i run my app in emulator.
public void OnCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.single_coll);
Button one = (Button) findViewById(R.id.all_stampii);
one.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), AllStampii.class);
startActivity(intent);
}
});}
single_coll.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="All Stampii" android:id="#+id/all_stampii" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Owned" android:id="#+id/owned" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Repeated" android:id="#+id/repeated" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Last Acquired" android:id="#+id/last_ac" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
There are no errors. I just can't see the Ui elements in emulator, in only this class.
Any suggestions?
I think you are having a minor problem in function declaration. What you have is:
public void OnCreate(Bundle savedInstanceState)
Make the 'OnCreate' to 'onCreate' and put #Override before the declaration.
You don't seem to be overriding the onCreate method. That means that the OnCreate method you've got there is not being called on startup.
If you change the first line to
#Override
public void onCreate(Bundle savedInstance){
(note the lower-case 'o' in onCreate)
then the method will be called correctly

How to change icon on the SlidingDrawer handle when clicked

Im trying to change the icon on the handle when i try to open the slidingdrawer.
When I extract the handle from the view and sets the onclicklistener or ontouchlistener it seems to never get trigget.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SlidingDrawer drawer = (SlidingDrawer)findViewById(R.id.drawer_landscape);
ImageView handle = (ImageView)findViewById(R.id.handle_l);
handle.setFocusable(true);
handle.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("test","onClick");
}
});
}
And my XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/base_frame_layout"
android:layout_gravity="bottom"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
</LinearLayout>
<SlidingDrawer
android:id="#+id/drawer_landscape"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:handle="#+id/handle_l"
android:content="#+id/content"
android:orientation="vertical"
android:visibility="visible"
>
<ImageView
android:id="#+id/handle_l"
android:layout_height="50px"
android:layout_width="64px"
android:padding="0px"
android:src="#drawable/icon"
/>
<TextView
android:id="#+id/content"
android:text="content"
android:layout_height="50px"
android:layout_width="64px"
/>
</SlidingDrawer>
</FrameLayout>
I was hoping this code should log "onClick" message, but it doesn't.
Any ideas?
I found it, it was pritty easy... I just need to setOnDrawerScrollListener on my drawer.
than implement the 2 methods onScrollEnded and onScrollStarted.
mSlidingDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener(){
#Override
public void onScrollEnded() {
// TODO Auto-generated method stub
Log.i("ddd","onScrollEnded slider");
slider_animation.reverseTransition(HANDLE_ANIMATION_SPEED);
}
#Override
public void onScrollStarted() {
// TODO Auto-generated method stub
Log.i("ddd","onScrollStarted slider");
slider_animation.startTransition(HANDLE_ANIMATION_SPEED);
}
});
I rather use an animation on the handle instead of changing the Image bacause of the flickering.
I found it for along time , but now it is completed about it .
It is the best way for Change Image Handle when you click to view SlidingDrawer.
It have 2 Method that we use in code below.
final SlidingDrawer drawer = (SlidingDrawer)findViewById(R.id.slidingDrawer);
drawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
arr.setImageResource(R.drawable.arrowdown);
}
});
drawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
arr.setImageResource(R.drawable.arrowup);
}
});

Categories

Resources